Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用未捕获的异常处理程序导致应用程序停止时应用程序崩溃_Android_Exception_Uncaughtexceptionhandler - Fatal编程技术网

Android 使用未捕获的异常处理程序导致应用程序停止时应用程序崩溃

Android 使用未捕获的异常处理程序导致应用程序停止时应用程序崩溃,android,exception,uncaughtexceptionhandler,Android,Exception,Uncaughtexceptionhandler,我正在使用未捕获异常处理程序捕获异常,但它会导致应用程序停止。我指的是这个帖子 还有这个 这是我的活动类,它反过来调用我的异常类 阅读完网址后,你就会知道我想要什么。。 我复制了未捕获的异常,这是 import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.content.Context; public class SRSDexception

我正在使用未捕获异常处理程序捕获异常,但它会导致应用程序停止。我指的是这个帖子 还有这个

这是我的活动类,它反过来调用我的异常类 阅读完网址后,你就会知道我想要什么。。 我复制了未捕获的异常,这是

import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.content.Context;

public class SRSDexception implements Thread.UncaughtExceptionHandler {

private Thread.UncaughtExceptionHandler defaultUEH;

private Activity app = null;

public SRSDexception(Activity app) {
this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
this.app = app;

}

public void uncaughtException(Thread t, Throwable e) 
{   
//  System.out.println("You crashed thread " + t.getName());
//    System.out.println("Exception was: " + e.toString());
StackTraceElement[] arr = e.getStackTrace();
String Raghav =t.toString();
String report = e.toString()+"\n\n";
report += "--------- Stack trace ---------\n\n"+Raghav;
for (int i=0; i<arr.length; i++)
{
report += "    "+arr[i].toString()+"\n";
}
report += "-------------------------------\n\n";

// If the exception was thrown in a background thread inside
// AsyncTask, then the actual exception can be found with getCause
report += "--------- Cause ---------\n\n";
Throwable cause = e.getCause();
if(cause != null) {
report += cause.toString() + "\n\n";
arr = cause.getStackTrace();
for (int i=0; i<arr.length; i++)
{
report += "    "+arr[i].toString()+"\n";
}
}
report += "-------------------------------\n\n";

try {
FileOutputStream trace = app.openFileOutput(
"stack.trace", Context.MODE_PRIVATE);
trace.write(report.getBytes());
trace.close();
} catch(IOException ioe) {
// ...
}

defaultUEH.uncaughtException(t, e);
}
我不知道问题是什么,可能是

  • 我的线程崩溃了
  • 我的处理程序未被调用
  • 或者它并没有将异常带到前台,但它会导致我的应用程序停止
  • 异常使它在以下情况下崩溃

  • 有人能帮我阻止这种停止吗使用ACRA(http://code.google.com/p/acra/) ! 他们做了你需要的事情,解决了你正在经历的问题

    不知道你在问什么或试图做什么。你不能缩进你的代码吗?(n eclipse选择块,使用源菜单将其右移,并将其粘贴到问题中)此外,给出堆栈跟踪please@Snicolas好的,我给你的是代码活动class@Snicolas是的,我已经按照您的说明更新了我的答案。我现在可以做什么?ACRA也可以用来捕获例外情况吗?您甚至可以查看网站吗?“ACRA是一个库,使Android应用程序能够自动将其崩溃报告发布到(…)您自己的自托管报表接收器脚本“
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    import android.app.Activity;
    import android.content.Context;
    
    public class SRSDexception implements Thread.UncaughtExceptionHandler {
    
    private Thread.UncaughtExceptionHandler defaultUEH;
    
    private Activity app = null;
    
    public SRSDexception(Activity app) {
    this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    this.app = app;
    
    }
    
    public void uncaughtException(Thread t, Throwable e) 
    {   
    //  System.out.println("You crashed thread " + t.getName());
    //    System.out.println("Exception was: " + e.toString());
    StackTraceElement[] arr = e.getStackTrace();
    String Raghav =t.toString();
    String report = e.toString()+"\n\n";
    report += "--------- Stack trace ---------\n\n"+Raghav;
    for (int i=0; i<arr.length; i++)
    {
    report += "    "+arr[i].toString()+"\n";
    }
    report += "-------------------------------\n\n";
    
    // If the exception was thrown in a background thread inside
    // AsyncTask, then the actual exception can be found with getCause
    report += "--------- Cause ---------\n\n";
    Throwable cause = e.getCause();
    if(cause != null) {
    report += cause.toString() + "\n\n";
    arr = cause.getStackTrace();
    for (int i=0; i<arr.length; i++)
    {
    report += "    "+arr[i].toString()+"\n";
    }
    }
    report += "-------------------------------\n\n";
    
    try {
    FileOutputStream trace = app.openFileOutput(
    "stack.trace", Context.MODE_PRIVATE);
    trace.write(report.getBytes());
    trace.close();
    } catch(IOException ioe) {
    // ...
    }
    
    defaultUEH.uncaughtException(t, e);
    }
    
    [android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314),   
    SRTekBox.Android.SRSD.SRSDAdvSearch.fnExpand(SRSDAdvSearch.java:390),  
    SRTekBox.Android.SRSD.SRSDAdvSearch$5.onClick(SRSDAdvSearch.java:209), 
    android.view.View.performClick(View.java:2408), android.view.View$PerformClick.run (View.java:8816),
    android.os.Handler.handleCallback(Handler.java:587),
    android.os.Handler.dispatchMessage(Handler.java:92),
    android.os.Looper.loop(Looper.java:123),
    android.app.ActivityThread.main(ActivityThread.java:4633),
    java.lang.reflect.Method.invokeNative(Native Method),
    java.lang.reflect.Method.invoke(Method.java:521),
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858),
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616),
    dalvik.system.NativeStart.main(Native Method)]