メールを送信するためのコードと、FORCE ERROR が発生した場合にスタック トレースを収集するためのコードの 2 つの部分を作成しました。これらのコードはどちらも個別に機能します。
今私の問題は、これらのコードの両方が機能しない場合です(ログも正常に機能しています)
public class BaseActivity extends Activity{
public Context context;
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
Writer result = new StringWriter();
PrintWriter printWriter = new PrintWriter(result);
paramThrowable.printStackTrace(printWriter);
System.out.println("BaseActivity.onCreate(...).new UncaughtExceptionHandler() {...}.uncaughtException()" +result.toString());
sendMail(result.toString());
Toast.makeText(getContext(),"cs", 1).show();
}
});
}
public void sendMail(String body){
try {
GMailSender sender = new GMailSender("email@gmail.com",
"password");
sender.sendMail("This is Subject",
"java.lang.RuntimeException: Unable to start activity ComponentInfo{com.silverSkills.com/com.silverSkills.com.ChildActivity}: java.lang.NullPointerException" +
"at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)" +
" at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)" +
" at android.app.ActivityThread.access$1500(ActivityThread.java:117)" +
" at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)" +
" at android.os.Handler.dispatchMessage(Handler.java:99)" +
" at android.os.Looper.loop(Looper.java:123)" +
" at android.app.ActivityThread.main(ActivityThread.java:3683)" +
" at java.lang.reflect.Method.invokeNative(Native Method)" +
" at java.lang.reflect.Method.invoke(Method.java:507)" +
" at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)" +
" at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)" +
" at dalvik.system.NativeStart.main(Native Method)" +
" Caused by: java.lang.NullPointerException" +
" at com.silverSkills.com.ChildActivity.onCreate(ChildActivity.java:9)" +
" at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)" +
" at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)" +
" ... 11 more",
"email@gmail.com", "email@gmail.com");
Log.i("Confirm","mail send");
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
}
}
そして、これがこのコードを呼び出す方法です。
public class ChildActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContext(this);
String a=null;
a.toString();
}
あなたが私に何か提案できるなら、それは素晴らしいことです:D