現在、画像r.drawable
をメールに添付して送信するアプリを開発しています。アプリのコードをアップロードしました。エミュレーターで強制終了し、logcat は nullpointerexception を示します。これを解決するのを手伝ってください。
画像(jpeg)をビットマップに変更し、バイト配列に変換しましたが、このバイト配列はlogcatでnullpointerexceptionを示していると思います.0の代わりに100または10,0000を行に与えてみましたmyLogo.compress(CompressFormat.JPEG,0, bos)
. それでも私のアプリは強制的に閉じられます.log catに同じエラーが表示されます. 解決を願っています。前もって感謝します。
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"));
}
});
}
}