记录和崩溃堆栈跟踪未在Android Studio中显示

时间:2015-01-08 13:58:35

标签: java android debugging android-studio

我正在尝试在我的设备上调试应用程序而且我在使用调试器时遇到了一些麻烦。我尝试测试记录器,看它是否会像这样写入Logcat:

Log.d("MyActivity", "Testing logging...");

但是在使用app: com.myapp.debug过滤器的Logcat中没有显示任何内容。当我只是按字符串过滤(使用我的应用程序名称)时出现,但条目如下所示:

01-08 13:45:07.468  29748-29748/? D/MyActivity﹕ Testing logging...

这个问号是否意味着应用中的某些内容没有传递给调试器?这可能与我调试器的第二个问题有关:

我一直在调试崩溃,每次发生时,手机只会显示“应用程序没有响应”消息,然后关闭当前活动,断开调试程序,并且应用程序继续运行上一个活动。没有堆栈跟踪,没有关于崩溃的信息,没有。我需要在Android Studio中设置一些内容才能使其正常工作吗?

3 个答案:

答案 0 :(得分:12)

我也有这个麻烦,我找不到太好的答案。 相反,我做了一个解决方法并使用Thread.setDefaultUncaughtExceptionHandler()捕获错误并使用Log.e()

记录它。

我用这个课来做。

  public class ExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {
   private final String LINE_SEPARATOR = "\n";
   public static final String LOG_TAG = ExceptionHandler.class.getSimpleName();

  @SuppressWarnings("deprecation")
  public void uncaughtException(Thread thread, Throwable exception) {
    StringWriter stackTrace = new StringWriter();
    exception.printStackTrace(new PrintWriter(stackTrace));

    StringBuilder errorReport = new StringBuilder();
    errorReport.append(stackTrace.toString());

    Log.e(LOG_TAG, errorReport.toString());

    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(10);
   }
}

然后在我的活动中。

   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /**
     * catch unexpected error
     */
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());

    setContentView(R.layout.activity_main);

    //other codes
   }

希望这有帮助。

答案 1 :(得分:4)

我认为这是同一个adb或filer问题。 首先删除所有过滤器。 重启adb - 输入终端adb kill-server&& adb start-server。

答案 2 :(得分:2)

可能您的Google分析“ga_reportUncaughtExceptions”设置为true,将其设置为false修复问题并将异常打印到logcat。有关详细信息,请参阅以下链接。

Why does android logcat not show the stack trace for a runtime exception?

相关问题