2

私はいくつかのAndroidアプリケーションを作成しましたが、いくつかのテストを行っているとクラッシュします。

しかし、クラッシュの理由がわからないので、クラッシュの理由をファイルに保存して、後でそれを確認できるようにする必要があります。アプリケーションの実行中にPCに接続しないため、保存するための提案が必要です。クラッシュの理由..?

4

5 に答える 5

1

以下のようにしてください。

try{
    //your code which throws exception
}
catch(Exception e){
   e.printStackTrace();   //optional

   //save your exception in a text file on sd-card
}

後でテキストファイルを読んで、例外を知ることができます

于 2012-08-22T16:19:25.143 に答える
1

私がこれまでに出くわした最良の方法は、インターネット許可を追加し、ACRAを使用することです。ACRAを使用すると、レポートをGoogle Docsスプレッドシートに送信でき、テストと本番環境で機能します。

ACRA以外に、2つのオプションがあります。

  1. エラーをスローする可能性のあるコードのすべてのビットをtry catchブロックで囲み、データをどこかに保存します。
  2. Thread.setDefaultUncaughtExceptionHandler()を使用して、未処理のすべての例外に対して呼び出されるハンドラーを設定できます。
于 2012-08-22T16:22:32.880 に答える
0

詳細が限られていることをお詫びしますが、Androidにはすでにロギングのオプションがありませんか?

http://developer.android.com/reference/android/util/Log.html

私はこれを試したことがなく、おそらくtry、catchの答えを選択するでしょうが、これは単なる別のオプションです。

于 2012-08-22T16:27:12.157 に答える
0

trycatchブロックを実行できます。

try {
    //the code lies here
} catch(Exception e) {
    //here you can save the e.toString() to a FileOutputStream and then save the file
}
于 2012-08-22T16:27:13.320 に答える
0

アプリケーションクラスを使用して「setDefaultUncaughtExceptionHandler」を設定する必要があります

public class YourApplication extends Application {

private Thread.UncaughtExceptionHandler defaultUEH;
// handler listener
private Thread.UncaughtExceptionHandler _unCaughtExceptionHandler =
        new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {

                // here I do logging of exception to a db
                PendingIntent myActivity = PendingIntent.getActivity(getApplicationContext(),
                        192837, new Intent(getApplicationContext(), YourActivity.class),
                        PendingIntent.FLAG_ONE_SHOT);

                AlarmManager alarmManager;
                alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                        15000, myActivity);
                System.exit(2);

                // re-throw critical exception further to the os (important)
                defaultUEH.uncaughtException(thread, ex);
            }
        };

public YourApplication() {
    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    // setup handler for uncaught exception
    Thread.setDefaultUncaughtExceptionHandler(_unCaughtExceptionHandler);
}

}

Androidマニフェストのアプリケーションタグにタグ名="your.app.application.YourApplication"を設定します

于 2014-07-01T12:46:08.233 に答える