我有问题。我的应用程序在启动时不断崩溃,但 logcat 什么也没告诉我。我试过 try-catch 但它仍然崩溃而没有留下任何东西。
这是我的 MainActivity.java:
public class MainActivity extends Activity
{
TextView logText;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
logText = (TextView) findViewById(R.id.log);
new Thread(new Runnable() {
@Override
public void run()
{
RestClient restClient = new HttpRestClient();
restClient.setUserAgent("IGN Score Joke Bot for /r/circlejerk");
User user = new User(restClient, "(My Username)", "(My Password)");
try
{
user.connect();
}
catch (Exception e)
{
e.printStackTrace();
}
Comments cmts = new Comments(restClient, user);
ExtendedComments exCmts = new ExtendedComments(cmts);
SubmitActions submitActions = new SubmitActions(restClient, user);
Submissions subms = new Submissions(restClient, user);
ExtendedSubmissions exSubms = new ExtendedSubmissions(subms);
boolean alreadyCmted;
while (true)
{
try
{
log("New loop started!");
List<Submission> submList = exSubms.ofSubreddit("circlejerk", SubmissionSort.NEW, 50);
for (Submission subm : submList)
{
List<Comment> cmtList = exCmts.ofSubmission(subm.getIdentifier(), CommentSort.NEW, 50, null);
for (Comment cmt : cmtList)
{
if (cmt.getBody().contains("/u/ign_score_bot score"))
{
alreadyCmted = false;
for (Comment rCmt : cmt.getReplies())
if (rCmt.getAuthor().equals("ign_score_bot"))
{
alreadyCmted = true;
}
if (!alreadyCmted)
{
log("Found Comment by " + cmt.getAuthor() + "! Commenting...");
submitActions.comment(cmt.getFullName(), new Random().nextInt(9) + "." + new Random().nextInt(9) + "/10 for this post/comment - IGN\n" + "Reasons:\n" + showReasons() + "\n\nI'ma unofficial IGN Score Robot for /r/circlejerk. Do not upvote me! Instead message /u/pongo1231 about how shitty this bot is, then message him feedback!");
}
}
}
}
log("Nothing went wrong. Puh! Now a Coffee Break for 30 secs...");
try
{
Thread.sleep(30000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
catch (RetrievalFailedException e)
{
log("Failed getting comment: " + e.getMessage());
}
}
}
}).run();
}
String showReasons()
{
int reasonsNum = new Random().nextInt(10);
String[] reasons = new String[] { "Not enough text", "Too much text",
"Needs more Upvotes", "Needs more Downvotes",
"Needs more Circlejerk", "Not enough jetfuel for steel beams",
"User needs more userness", "Not good enough graphics",
"Needs more colors", "Needs more IGN", "This Bot sucks",
"Needs more Reddit", "*Nonsense*", "Not mainstream enough",
"Not Spacejam enough", "sdwsyxsawdasdaasdwasadassdaas",
"Beep Boop", "Needs to be posted on /r/funny",
"Not enough Wall Of Text", "Needs more Dank" };
StringBuilder builder = new StringBuilder();
for (int i = 0; i < reasonsNum; i++)
{
builder.append("- " + reasons[new Random().nextInt(reasons.length)] + "\n");
}
return builder.toString();
}
void log(final String text)
{
try {
logText.setText(logText.getText() + "\n" + text);
} catch (Exception e) {
System.out.println(e.getCause());
}
}
}
可能是因为堆大小太小?我有
android:largeHeap="true"
在我的 AndroidManifest.xml 中,但我不确定它是否仍然使用太多资源。
互联网权限也不是问题,我已经在我的 AndroidManifest.xml 中设置了它
<uses-permission android:name="android.permission.INTERNET" />
我试图设置断点,它似乎在该行崩溃
restClient.setUserAgent("IGN Score Joke Bot for /r/circlejerk");
任何帮助,将不胜感激!
编辑:我发现每次我的应用程序崩溃时logcat都会说:
Error opening /proc/29336/oom_score_adj; errno=2
这不是我的应用程序中的包名称或其他名称,但这可能取决于我的应用程序吗?