参考:https://trivedihardik.wordpress.com/2011/08/20/how-to-avoid-force-close-error-in-android/
我使用此系统不显示强制关闭错误对话框。虽然它可以在我的其他每个项目中运行,但我的主要项目因此而陷入循环。(" HataSayfasi"尝试一次又一次地启动,实际上它运行并且我在这个类中记录了日志消息但它没有&#39 ; t出现屏幕并尝试重新开始。)可能出现的问题是什么?我怎么能克服它? 处理程序类:
public class ExceptionHandlerForceClose implements java.lang.Thread.UncaughtExceptionHandler {
private final Activity myContext;
private final String LINE_SEPARATOR = "\n";
public ExceptionHandlerForceClose(Activity context) {
Log.i("tago" , "Handler oluşturuldu");
myContext = context;
}
public void uncaughtException(Thread thread, Throwable exception) {
Log.i("tago", "Handler exception oluşturuldu");
StringWriter stackTrace = new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));
StringBuilder errorReport = new StringBuilder();
errorReport.append("************ CAUSE OF ERROR ************\n\n");
errorReport.append(stackTrace.toString());
errorReport.append("\n************ DEVICE INFORMATION ***********\n");
errorReport.append("Brand: ");
errorReport.append(Build.BRAND);
errorReport.append(LINE_SEPARATOR);
errorReport.append("Device: ");
errorReport.append(Build.DEVICE);
errorReport.append(LINE_SEPARATOR);
errorReport.append("Model: ");
errorReport.append(Build.MODEL);
errorReport.append(LINE_SEPARATOR);
errorReport.append("Id: ");
errorReport.append(Build.ID);
errorReport.append(LINE_SEPARATOR);
errorReport.append("Product: ");
errorReport.append(Build.PRODUCT);
errorReport.append(LINE_SEPARATOR);
errorReport.append("\n************ FIRMWARE ************\n");
errorReport.append("SDK: ");
errorReport.append(Build.VERSION.SDK);
errorReport.append(LINE_SEPARATOR);
errorReport.append("Release: ");
errorReport.append(Build.VERSION.RELEASE);
errorReport.append(LINE_SEPARATOR);
errorReport.append("Incremental: ");
errorReport.append(Build.VERSION.INCREMENTAL);
errorReport.append(LINE_SEPARATOR);
Log.i("tago", "Handler errorreport olusturuldu");
Log.i("tago", "Handler Error :" + errorReport.toString());
Intent intent = new Intent(myContext, HataSayfasi.class);
Log.i("tago", "Handler intent1");
intent.putExtra("error", errorReport.toString());
Log.i("tago", "Handler intent2");
myContext.startActivity(intent);
Log.i("tago", "Handler intent3");
android.os.Process.killProcess(android.os.Process.myPid());
Log.i("tago", "Handler intent4");
System.exit(0);
Log.i("tago" , "Handler intent5");
}
}
" HataSayfasi" class:
public class HataSayfasi extends Activity {
protected void onCreate(Bundle bambam){
super.onCreate(bambam);
Log.i("tago" , "Handler hatasayfasi olusturuldu");
ExceptionHandlerForceClose exceptionhandler = new ExceptionHandlerForceClose(this);
Log.i("tago" , "Handler hatasayfasi olusturuldu1");
Thread.setDefaultUncaughtExceptionHandler(exceptionhandler);
Log.i("tago", "Handler hatasayfasi olusturuldu2");
setContentView(R.layout.hatasayfasi);
Log.i("tago", "Handler hatasayfasi olusturuldu3");
Intent i = getIntent();
Log.i("tago" , "Handler hatasayfasi olusturuldu4");
String hata = i.getStringExtra("error");
Log.i("tago" , "Handler hatasayfasi olusturuldu5");
TextView tv1 = (TextView) findViewById(R.id.textView25);
Log.i("tago" , "Handler hatasayfasi olusturuldu6");
tv1.setText(hata);
}
" AnaAkim(此处引用的上下文)类onCreate:
protected void onCreate(Bundle bambam) {
super.onCreate(bambam);
ExceptionHandlerForceClose exceptionhandler = new ExceptionHandlerForceClose(this);
Thread.setDefaultUncaughtExceptionHandler(exceptionhandler);
setContentView(R.layout.genelaltplan);
Integer.parseInt("324234");
sharedkullaniciciktikaydet(false);
notificationSharedPrefKaydet(true);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
aramasistemi();
tanimlar();
nickAl();
}
我使用Integer.parseInt(" dgfsfdg")来获取错误。我的服务或其他任何我无法理解的问题导致此类问题?