2016-07-03 13 views
-2

由於某些原因在@overide部分,它說'方法不會覆蓋它的超類中的方法'。我如何解決這個問題?由於某些原因在@overide部分它說'方法不會覆蓋它的超類的方法'。我如何解決這個問題?

public class Main6Activity extends AppCompatActivity { 
    private Button buttonChoose; 
    private Button buttonUpload; 

    private ImageView imageView; 

    private EditText editTextName; 

    private Bitmap bitmap; 

    private int PICK_IMAGE_REQUEST = 1; 

    private String UPLOAD_URL = "http://simplifiedcoding.16mb.com/VolleyUpload/upload.php"; 

    private String KEY_IMAGE = "image"; 
    private String KEY_NAME = "name"; 

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

     buttonChoose = (Button) findViewById(R.id.buttonChoose); 
     buttonUpload = (Button) findViewById(R.id.buttonUpload); 

     editTextName = (EditText) findViewById(R.id.editText); 

     imageView = (ImageView) findViewById(R.id.imageView); 

     buttonChoose.setOnClickListener(this); 
     buttonUpload.setOnClickListener(this); 
    } 

    public String getStringImage(Bitmap bmp) { 
     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
     byte[] imageBytes = baos.toByteArray(); 
     String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); 
     return encodedImage; 

    private void uploadImage() { 
     //Showing the progress dialog 
     final ProgressDialog loading = ProgressDialog.show(this, "Uploading...", "Please wait...", false, false); 
     StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, 
       new Response.Listener<String>() { 
        @Override 
        public void onResponse(String s) { 
         //Disimissing the progress dialog 
         loading.dismiss(); 
         //Showing toast message of the response 
         Toast.makeText(Main6Activity.this, s, Toast.LENGTH_LONG).show(); 
        } 
       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError volleyError) { 
         //Dismissing the progress dialog 
         loading.dismiss(); 

         //Showing toast 
         Toast.makeText(Main6Activity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show(); 
        } 
       }) { 
      @Override 
      protected Map<String, String> getParams() throws AuthFailureError { 
       //Converting Bitmap to String 
       String image = getStringImage(bitmap); 

       //Getting Image Name 
       String name = editTextName.getText().toString().trim(); 

       //Creating parameters 
       Map<String, String> params = new Hashtable<String, String>(); 

       //Adding parameters 
       params.put(KEY_IMAGE, image); 
       params.put(KEY_NAME, name); 

       //returning parameters 
       return params; 
      } 
     }; 


     RequestQueue requestQueue = Volley.newRequestQueue(this); 


     //Adding request to the queue 
     requestQueue.add(stringRequest); 
    } 

    private void showFileChooser() { 
     Intent intent = new Intent(); 
     intent.setType("image/*"); 
     intent.setAction(Intent.ACTION_GET_CONTENT); 
     startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 

     if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { 
      Uri filePath = data.getData(); 
      try { 
       //Getting the Bitmap from Gallery 
       bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath); 
       //Setting the Bitmap to ImageView 
       imageView.setImageBitmap(bitmap); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 


    } 

    @Override 
    public void onClick(View v) { 

     if (v == buttonChoose) { 
      showFileChooser(); 
     } 

     if (v == buttonUpload) { 
      uploadImage(); 


     } 
    } 


} 

三江源和幫助,將不勝感激。 由於某些原因在@overide部分它說'方法不會覆蓋它的超類的方法'。我如何解決這個問題?

+0

你還沒有實現onClickListener接口,這就是爲什麼你有這個消息 –

回答

0

這意味着你的方法有其聲明不完善,可能缺少一些部分。查看哪個方法引發了錯誤,並在Web上搜索此強制方法的模式聲明。

0

我認爲「不覆蓋」的抱怨是針對onClick()方法的。 AppCompatActivity沒有這種方法。你的Main6Activity類需要實現View.OnClickListener接口,如下所示:

public class Main6Activity extends AppCompatActivity implements View.OnClickListener { 
相關問題