目前我正在开发一个应用程序,它将图像r.drawable
作为附件发送到电子邮件,我已经上传了我的应用程序的代码,它在模拟器中强制关闭,并且 logcat 显示 nullpointerexception。请帮我解决这个问题。
我已将图像(jpeg)更改为位图,并将其转换为字节数组,并且我认为该字节数组在 logcat 中显示 nullpointerexception,我也尝试在行中给出 100 或 10,0000 而不是 0 myLogo.compress(CompressFormat.JPEG,0, bos)
。而且我的应用程序仍然强制关闭。在日志猫中显示相同的错误。希望有解决办法。先感谢您。
package com.email;
import java.io.ByteArrayOutputStream;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class home extends Activity {
/** Called when the activity is first created. */
EditText ed1,ed2,ed3;
Drawable myDrawable = getResources().getDrawable(R.drawable.aish);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
ed1=(EditText)findViewById(R.id.editText1);
ed2=(EditText)findViewById(R.id.editText2);
ed3=(EditText)findViewById(R.id.editText3);
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String ids=ed1.getText().toString();
String id[]={ids};
String sub=ed2.getText().toString();
String msg=ed3.getText().toString();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
myLogo.compress(CompressFormat.JPEG,0, bos);
Intent in=new Intent(Intent.ACTION_SEND);
in.setData(Uri.parse("MailTo:"));
in.setType("plain/text");
in.putExtra(Intent.EXTRA_EMAIL,id);
in.putExtra(Intent.EXTRA_SUBJECT,sub);
in.putExtra(Intent.EXTRA_TEXT,msg);
in.setType("image/jpg");
in.putExtra(Intent.EXTRA_STREAM,bos.toByteArray());
startActivity(Intent.createChooser(in, "Email"));
}
});
}
}