0

大家早上好,我是一个没有经验的开发人员,我需要你..
我有这个代码来选择图像并发送(到附件)电子邮件......请帮助我,因为这个代码失败了。

private static int RESULT_LOAD_IMAGE = 1;
private static final int PICK_FROM_GALLERY = 2;
private static final int REQ_CODE_PICK_IMAGE = 0;
Uri selectedImage;

public void galleria(View v){
     Intent in = new        Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
         startActivityForResult(in, RESULT_LOAD_IMAGE);  
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

        switch(requestCode) { 
        case REQ_CODE_PICK_IMAGE:
        if(resultCode == RESULT_OK){  
           Uri selectedImage = imageReturnedIntent.getData();         
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
          emailIntent.setType("plain/text");
          emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"stefano.pietrella@gmail.com"});
          emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Object");
          emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Message...");

                            //Uri attachment = Uri.parse("file:///sdcard/fil.txt");
          emailIntent.putExtra(Intent.EXTRA_STREAM,selectedImage);
          startActivity(Intent.createChooser(emailIntent, "Send email..."));            
            }
        }
    }

日志猫

02-21 09:53:20.359: E/AndroidRuntime(16440): FATAL EXCEPTION: 
main 02-21 09:53:20.359: E/AndroidRuntime(16440): java.lang.IllegalStateException: 
Could not find a method k(View) in the activity class com.supermoney.campionatoruzzle.LeagueSummaryV2 for onClick handler on view class android.widget.Button with id 'buttonStartMatch2' 
02-21 09:53:20.359: E/AndroidRuntime(16440): at android.view.View$1.onClick(View.java:3678) 
02-21 09:53:20.359: E/AndroidRuntime(16440): at android.view.View.performClick(View.java:4211)
4

1 回答 1

0

从您的日志 cat 稍后发表的评论中,您似乎在 xml 中放置了一个 onclick 方法 k 并且在 java 计数器部分中没有声明

private static int RESULT_LOAD_IMAGE = 1;
    private static final int PICK_FROM_GALLERY = 2;
    private static final int REQ_CODE_PICK_IMAGE = 0;
    Uri selectedImage;

public void galleria(View v){
 Intent in = new        Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
     startActivityForResult(in, RESULT_LOAD_IMAGE);  
}

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case REQ_CODE_PICK_IMAGE:
    if(resultCode == RESULT_OK){  
       Uri selectedImage = Uri.parse("file://"+  getRealPathFromURI(imageReturnedIntent.getData());         
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
      emailIntent.setType("plain/text");
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"stefano.pietrella@gmail.com"});
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Object");
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Message...");

                        //Uri attachment = Uri.parse("file:///sdcard/fil.txt");
      emailIntent.putExtra(Intent.EXTRA_STREAM,selectedImage);
      startActivity(Intent.createChooser(emailIntent, "Send email..."));            
        }
    }
}

好像你从画廊而不是路径中选择它返回一个内容:// uri

         Uri selectedImage = Uri.parse("file://"+  getRealPathFromURI(imageReturnedIntent.getData())

试试这个——如果从画廊和文件管理器去你以前的内容可以在一个if条件检查天气里完成

   public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    if (cursor == null) {
        return null;
    }
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
于 2013-02-21T08:57:09.163 回答