我遇到了问题。当我启动它时,我的应用程序不断崩溃,但是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
这不是我的应用程序中的软件包名称或其他内容,但可能取决于我的应用程序?