-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugActivity.java
76 lines (62 loc) · 2.01 KB
/
DebugActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.protecgames.htmleditor;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import java.io.InputStream;
public class DebugActivity extends Activity {
private String[] exceptionTypes = {
"StringIndexOutOfBoundsException",
"IndexOutOfBoundsException",
"ArithmeticException",
"NumberFormatException",
"ActivityNotFoundException"
};
private String[] exceptionMessages = {
"Invalid string operation\n",
"Invalid list operation\n",
"Invalid arithmetical operation\n",
"Invalid toNumber block operation\n",
"Invalid intent operation"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String errorMessage = "";
String madeErrorMessage = "";
if (intent != null) {
errorMessage = intent.getStringExtra("error");
String[] split = errorMessage.split("\n");
//errorMessage = split[0];
try {
for (int j = 0; j < exceptionTypes.length; j++) {
if (split[0].contains(exceptionTypes[j])) {
madeErrorMessage = exceptionMessages[j];
int addIndex = split[0].indexOf(exceptionTypes[j]) + exceptionTypes[j].length();
madeErrorMessage += split[0].substring(addIndex, split[0].length());
madeErrorMessage += "\n\nDetailed error message:\n" + errorMessage;
break;
}
}
if (madeErrorMessage.isEmpty()) {
madeErrorMessage = errorMessage;
}
} catch (Exception e) {
madeErrorMessage = madeErrorMessage + "\n\nError while getting error: " + Log.getStackTraceString(e);
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("An error occurred");
builder.setMessage(madeErrorMessage);
builder.setPositiveButton("End Application", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.create().show();
}
}