2016-06-25 23 views
-3

由於某種原因,當我把'NameValuePair'它說不能解析符號。我該如何解決這個問題?由於某些原因,當我把'NameValuePair'它說不能解析符號。我該如何解決這個問題?

代碼:

public class MainActivity extends AppCompatActivity implements View.OnClickListener { 
    private static final int RESULT_LOAD_IMAGE = 1; 

    ImageView imageToUpload, downloadedImage; 
    Button bUploadImage, bDownloadImage; 
    EditText uploadImageName, downloadImageName; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     imageToUpload = (ImageView) findViewById(R.id.imageToUpload); 
     downloadedImage = (ImageView) findViewById(R.id.downloadedImage); 

     bUploadImage = (Button) findViewById(R.id.bUploadImage); 
     bDownloadImage = (Button) findViewById(R.id.bDownloadImage); 

     uploadImageName = (EditText) findViewById(R.id.etUploadName); 
     downloadImageName = (EditText) findViewById(R.id.etDownloadName); 

     imageToUpload.setOnClickListener(this); 
     bUploadImage.setOnClickListener(this); 
     bDownloadImage.setOnClickListener(this); 




} 


    @Override 
    public void onClick(View v) { 
     switch(v.getId()){ 
      case R.id.imageToUpload: 
       Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE); 
       break; 
      case R.id.bUploadImage: 
       Bitmap Image = ((BitmapDrawable) imageToUpload.getDrawable()).getBitmap(); 




       break; 
      case R.id.bDownloadImage: 

       break; 

     } 


    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == RESULT_LOAD_IMAGE && resultCode ==RESULT_OK && data != null) { 
      Uri selectedImage = data.getData(); 
      imageToUpload.setImageURI(selectedImage); 
     } 

     } 

     private class UploadImage extends AsyncTask<Void, Void, Void>{ 

      Bitmap image; 
      String name; 

      public UploadImage(Bitmap image, String name) { 
       this.image = image; 
       this.name = name; 
      } 

      @Override 
      protected void onPostExecute(Void aVoid) { 

       super.onPostExecute(aVoid); 
      } 

      @Override 
      protected Void doInBackground(Void... params) { 
       ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 
       image.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); 
       String encodedImage = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT); 

       ArrayList<NameValuePair> dataToSend = new ArrayList<>(); 
       dataToSend.add(new BasicNameValuePair("image")); 


       return null; 
      } 
     } 

    } 

如何解決 '的NameValuePair' 的錯誤? 幫助將不勝感激解決這個錯誤。

三江源

+1

https://stackoverflow.com/questions/32949626/org-apache-http-entity-fileentity-is-deprecated-in-android-6-marshmallow HttpClient及其相關類如'NameValuePair',已棄用Android 5.1並在Android 6.0的SDK中刪除。 – CommonsWare

+0

它是否在您的進口中列出?或者你甚至沒有嘗試導入課堂? – f1sh

回答

-1

重命名NameValuePairBasicNameValuePair它會對你有幫助。

+1

它不起作用 –

+0

@LucyMatthew是對的,這是行不通的。 –

相關問題