安装后运行Android应用程序崩溃

时间:2013-08-10 12:19:56

标签: android eclipse

我正在开发一个原生的android应用程序,我也在使用第三方api。问题是,当我将移动设备(S3)连接到我的机器并直接在移动设备上运行应用程序时,它工作正常。但是当我将APK复制到Android手机时,安装了APP并运行。然后在其中一个api上调用它崩溃说"不幸的是AppName停止了工作"。

我找不到任何方法来找出问题是什么以及应用程序崩溃的原因是什么。

任何人都建议如何找出问题或可能的问题。我正在Eclipse中开发。

3 个答案:

答案 0 :(得分:1)

为什么不设置一个5分钟的快速BugSense库和免费帐户,并检查您获得的例外情况? http://www.bugsense.com/

答案 1 :(得分:1)

您可以通过在应用中实施java.lang.Thread.UncaughtExceptionHandler来设置自己的日志编写系统。

e.g。

public class myExceptionHandler implements UncaughtExceptionHandler {

private UncaughtExceptionHandler defaultUEH;

private String localPath;



public myExceptionHandler(String localPath) {
    this.localPath = localPath;

    this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
}

@Override
public void uncaughtException(Thread t, Throwable e) {
    final long ts = new Date().getTime();

    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(ts);

    final String timestamp = new SimpleDateFormat("HH_mm_ss_SSS")
            .format(cal.getTime());

    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);
    String stacktrace = result.toString();
    printWriter.close();
    String filename = "logcat"+timestamp + ".txt";

    if (localPath != null) {

        writeToFile(stacktrace, filename);
    }

    defaultUEH.uncaughtException(t, e);

}

private void writeToFile(String stacktrace, String filename) {
    try {
        BufferedWriter bos = new BufferedWriter(new FileWriter(localPath
                + "/" + filename));
        bos.write(stacktrace);
        bos.flush();
        bos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

从MainActivity中调用此处理程序,如下所示:

  Thread.setDefaultUncaughtExceptionHandler(new myExceptionHandler("Put your target directory/folder path where you would like to store the log file"));

现在,只要应用程序在代码中使用的文件夹中崩溃,您就会编写一个日志文件。

答案 2 :(得分:0)

只需将设备连接到PC,然后打开Eclipse中的LogCat窗口即可。 Logcat消息仍将输出到LogCat,而无需实际调试您的应用程序。