メールを送信する必要があるため、クラスを作成しましたが、startActivity(intent) にエラーが表示されます。このコードはメイン アクティビティでうまく機能します。ここにコード:
public class SendEmail extends Activity {
private String emailTo;
private String subject;
private String message;
public SendEmail(String AEmailTo, String ASubject, String AMessage) {
this.emailTo = AEmailTo;
this.subject = ASubject;
this.message = AMessage;
}
public void Send(){
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/octet-stream");
intent.putExtra(Intent.EXTRA_SUBJECT, this.subject);
intent.putExtra(Intent.EXTRA_TEXT, this.message);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {this.emailTo});
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
}
}
LogCat:
11-12 10:54:56.783: E/SendMail(19773): null
11-12 10:54:56.783: E/SendMail(19773): java.lang.NullPointerException
11-12 10:54:56.783: E/SendMail(19773): at android.app.Activity.startActivityForResult(Activity.java:2817)
11-12 10:54:56.783: E/SendMail(19773): at android.app.Activity.startActivity(Activity.java:2923)
11-12 10:54:56.783: E/SendMail(19773): at idealbrasil.forcav.android.SendEmail.Send(SendEmail.java:52)
11-12 10:54:56.783: E/SendMail(19773): at idealbrasil.forcav.android.util.funcoes.SendEmail(funcoes.java:221)
11-12 10:54:56.783: E/SendMail(19773): at idealbrasil.forcav.android.util.TrataErro$1.onClick(TrataErro.java:136)
11-12 10:54:56.783: E/SendMail(19773): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
11-12 10:54:56.783: E/SendMail(19773): at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 10:54:56.783: E/SendMail(19773): at android.os.Looper.loop(Looper.java:123)
11-12 10:54:56.783: E/SendMail(19773): at android.app.ActivityThread.main(ActivityThread.java:4627)