我有一個類(在它自己的文件)UncaughtExceptionHandler的概率
public class UncaughtExceptionHandler implements
java.lang.Thread.UncaughtExceptionHandler
在我的主要程序中,我有以下幾點: -
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
當編譯我收到以下錯誤: -
cannot instantiate the type Thread.UncaughtExceptionHandler
我在這裏錯過了一些基本點嗎?
這裏是代碼: import java.io. *;
import android.content。*;
public class UncaughtExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {0} {0}私有最終上下文myContext;
public UncaughtExceptionHandler(Context context) {
myContext = context;
}
public void uncaughtException(Thread thread, Throwable exception) {
boolean crashedOnLastClose = false;
MyApplication.writeProgressLog("before isfinishing".ERROR_FILE_NAME);
// The application is being destroyed by the O/S
crashedOnLastClose = true;
MyApplication.writeProgressLog("after isfinishing",ERROR_FILE_NAME);
}
}
您是否正在實現接口的所有方法? – Viren
你必須重寫方法[uncaughtException(Thread,Throwable)](http://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html#uncaughtException%28java.lang.Thread,%20java.lang。 Throwable%29) –
當**編譯**或**運行時**您的程序出現錯誤?在編譯時得到「無法實例化類型」錯誤似乎很奇怪...... – BegemoT