Reputation: 353
I am working on a simple android project but have encountered a dreaded FATAL EXCEPTION, and don't really have the know-how to determine if I am doing something off limits in the world of Android... I have this code:
private OnClickListener butonList_start = new OnClickListener(){
public void onClick(View v){
Toast.makeText(getBaseContext(), "Good Luck.", Toast.LENGTH_LONG).show();
otherBtn_1.setOnClickListener(otherListener_1);
otherBtn_2.setOnClickListener(otherListener_2);
aTextView.setTextSize(30);
aTextView.setText("");
aTextView.setMaxLines(1);
}
};
All of this executes without a hitch, until at the very end I enter this:
activate();
Which is a reference to this code:
private void activate(){
setImage_AS();
first = selector1_AS();
second = selector2_AS();
aTextView_2.setText(first);
aTextView_3.setText(second);
}
private void setImage_AS(){
int xxx = randm.nextInt(2);
if(xxx==0){
image.setImageResource(R.drawable.crew_31242514);
int op = 0;
}
if(xxx==1){
image.setImageResource(R.drawable.ic_launcher);
int op = 1;
}
}
private int selector1_AS(){
return randm.nextInt(50);
}
private int selector2_AS(){
return randm.nextInt(first);
}
Through the method "activate" I set the image of a pre-defined ImageView, and give both 'first' and 'second' value through their respective methods which randomly assign values within those parameters.
Now, nothing else happens after this unless a user presses a button, so, the error should be in here right? What am I doing wrong, I've looked over this so much but can't get any hints from the LogCat which just returns FATAL EXCEPTION and no details (unless I cannot see them).
My code has no errors and therefore no references to objects or types that haven't been declared, and everything runs smoothly in the app until the button that activates butonList_start is clicked. Please help me!
Here're the LogCat lines
FOUND THE ISSUE Still a tad Confused
The issue was a product of my attempts to set the text of the TextView to the value given by 'first' or 'second', which was an int... But why would that be a problem, will setText() only accept Strings?
Upvotes: 0
Views: 45
Reputation: 1600
Look at line 63 of Basic.java in your activate() method. You are trying to set the text of a text view to an int. I would guess it is the line aTextView_2.setText(first);
.
So, TextView has a method setText(int) that expect that int to be a string resource id. There is no string resource that matches the id you have given it and so the exception is thrown.
If you want to display an integer's value in a TextView try using something like myTextView.setText( String.valueOf( someInteger ) );
instead. This method, setText(CharSequence), takes a CharSequence and will allow you to directly specify the text you want to be displayed in the TextView
Upvotes: 2