-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugActivity.java
More file actions
69 lines (53 loc) · 2.24 KB
/
DebugActivity.java
File metadata and controls
69 lines (53 loc) · 2.24 KB
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
package com.htmledit.editor;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.util.Log;
import android.widget.HorizontalScrollView;
import android.widget.ScrollView;
import android.widget.TextView;
import java.util.HashMap;
import java.util.Map;
public class DebugActivity extends Activity {
private static final Map<String, String> exceptionMap = new HashMap<String, String>() {{
put("StringIndexOutOfBoundsException", "Invalid string operation\n");
put("IndexOutOfBoundsException", "Invalid list operation\n");
put("ArithmeticException", "Invalid arithmetical operation\n");
put("NumberFormatException", "Invalid toNumber block operation\n");
put("ActivityNotFoundException", "Invalid intent operation\n");
}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SpannableStringBuilder formattedMessage = new SpannableStringBuilder();
Intent intent = getIntent();
String errorMessage = "";
if (intent != null) {
errorMessage = intent.getStringExtra("error");
}
if (!errorMessage.isEmpty()) {
String[] split = errorMessage.split("\n");
String exceptionType = split[0];
String message = exceptionMap.getOrDefault(exceptionType, "");
if (!message.isEmpty()) {
formattedMessage.append(message);
}
for (int i = 1; i < split.length; i++) {
formattedMessage.append(split[i]);
formattedMessage.append("\n");
}
} else {
formattedMessage.append("No error message available.");
}
setTitle(getTitle() + " Crashed");
TextView errorView = new TextView(this);
errorView.setText(formattedMessage);
errorView.setTextIsSelectable(true);
HorizontalScrollView hscroll = new HorizontalScrollView(this);
ScrollView vscroll = new ScrollView(this);
hscroll.addView(vscroll);
vscroll.addView(errorView);
setContentView(hscroll);
}
}