I've got a problem. My app keeps crashing when I start it, but the logcat tells me nothing. I've tried try-catch but it still crashes without leaving something.
Here's my 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());
}
}
}
Might it be because of too less heap size? I have got
android:largeHeap="true"
in my AndroidManifest.xml but I'm not sure if it still uses too much resources.
It's not a problem with the internet permissions too, I've got it set in my AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
I've tried to set breakpoints and it seems to crash at the line
restClient.setUserAgent("IGN Score Joke Bot for /r/circlejerk");
Any help would be appreciated!
EDIT: I've found that the logcat says following every time my app crashes:
Error opening /proc/29336/oom_score_adj; errno=2
That's not the package name or something else from my app, but might that be dependent on my app?