http.post.setentity在带有多官能设备布构建的错误上



我试图将我的Android应用程序连接到我遇到此问题时在Localhost上的烧瓶服务器。为了更容易检测错误,我将让您允许您的Android应用程序的代码和Android Studio日志的输出。

首先,我的Android应用程序的代码:仅在触摸设备的屏幕时尝试将图像上传到服务器。该代码尚未完成,因为我在结束错误之前检测到错误。

public class Imagen extends ActionBarActivity {
private int SELECT_IMAGE = 237;
private int TAKE_PICTURE = 829;
private int n_touchs=0;
private EditText lblPhoto;
private ImageView imgPhoto;
private RelativeLayout world;
private HttpClient client=new DefaultHttpClient();
private HttpPost post=new HttpPost("192.168.1.138");
private MultipartEntityBuilder builder=MultipartEntityBuilder.create();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imagen);
    lblPhoto=(EditText)findViewById(R.id.lblPhoto);
    imgPhoto=(ImageView)findViewById(R.id.imgPhoto);
    world=(RelativeLayout)findViewById(R.id.world);
    world.setOnTouchListener(new RelativeLayout.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (n_touchs == 0) {
                dialogPhoto();
                n_touchs++;
            }
            return true;
        }
    });
}
private void dialogPhoto(){
    try{
        final CharSequence[] items = {"Seleccionar de la galería", "Hacer una foto"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Seleccionar una foto");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                switch(item){
                    case 0:
                        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                        intent.setType("image/*");
                        startActivityForResult(intent, SELECT_IMAGE);
                        break;
                    case 1:
                        startActivityForResult(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE), TAKE_PICTURE);
                        break;
                }
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    } catch(Exception e){}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_imagen, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try{
        if (requestCode == SELECT_IMAGE) {
            if (resultCode == Activity.RESULT_OK) {
                Uri selectedImage = data.getData();
                lblPhoto.setText("ok");
                imgPhoto.setImageURI(selectedImage);
                File file_image=new File(selectedImage.toString());
                FileBody file_send=new FileBody(file_image);
                builder.addPart("file",file_send);
                HttpEntity entity=builder.build();
                post.setEntity(entity);
            }
        }
        if(requestCode == TAKE_PICTURE) {
            if (resultCode == Activity.RESULT_OK) {
                Uri selectedImage = data.getData();
                lblPhoto.setText("ok");
                imgPhoto.setImageURI(selectedImage);
                File file_image=new File(selectedImage.toString());
                FileBody file_send=new FileBody(file_image);
                builder.addPart("file",file_send);
                post.setEntity(builder.build());
            }
        }
    } catch(Exception e){}
}

}

我的日志输出是:

05-05 20:01:41.761: E/AndroidRuntime(11109): FATAL EXCEPTION: main
05-05 20:01:41.761: E/AndroidRuntime(11109): java.lang.NoSuchFieldError: org.apache.http.message.BasicHeaderValueFormatter.INSTANCE
05-05 20:01:41.761: E/AndroidRuntime(11109):    at org.apache.http.entity.ContentType.toString(ContentType.java:153)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at org.apache.http.entity.mime.MultipartFormEntity.<init>(MultipartFormEntity.java:52)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at org.apache.http.entity.mime.MultipartEntityBuilder.buildEntity(MultipartEntityBuilder.java:226)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at org.apache.http.entity.mime.MultipartEntityBuilder.build(MultipartEntityBuilder.java:230)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at com.example.bryan.imagen.Imagen.onActivityResult(Imagen.java:122)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.app.Activity.dispatchActivityResult(Activity.java:5563)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3514)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3561)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.app.ActivityThread.access$1200(ActivityThread.java:168)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1377)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.os.Looper.loop(Looper.java:137)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at android.app.ActivityThread.main(ActivityThread.java:5493)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at java.lang.reflect.Method.invoke(Method.java:525)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
05-05 20:01:41.761: E/AndroidRuntime(11109):    at dalvik.system.NativeStart.main(Native Method)

我希望您能为我提供这个错误和英语的错误。谢谢。

我在看到此帖子时正在阅读堆栈中的帖子:

有解决我问题的解决方案。

相关内容

  • 没有找到相关文章

最新更新