Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmichaelconnolly
848 PointsErrors. Please help.
Can someone please help. I'm trying to do the fun fact app. I've added the button and the fun fact. When I bring up the emulator I can see the button but can't click on it. This is my java code.
package com.connmics.funfacts;
import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;
public class FunFactsActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
TextView factLabel = (TextView) findViewById(factTextView) ;
Button showFactButton = (Button) findViewById(R.id.showFactButton) ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_fun_facts, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
} It says it can't fine symbols for class textview and class button. Or variable textview. I think I followed all the steps to this point, But something is wrong. If anyone can please let me know what I'm doing wrong. Thanks for any help..
9 Answers
James Simshaw
28,738 PointsHello,
Currently your button doesn't have any click behavior defined(at least in the java file provided). Keep going through the course and you will eventually add the ability to do things when the button is pressed. So far, you should just be able to see the button.
James Simshaw
28,738 PointsHello,
On another go through your code, I was able to see one code issue(I would recommend to learn and use markdown when posting code since it provides syntax coloring which can help to make errors pop out when reading the code). In your line
TextView factLabel = (TextView) findViewById(factTextView) ;
You should be referring to R.id.factTextView
TextView factLabel = (TextView) findViewById(R.id.factTextView) ;
You also need to make sure you import the Button and TextView classes, add the following lines with the rest of the import statements
import android.widget.Button;
import android.widget.TextView;
Something else you could do as well that would automatically generate the above two lines is to put your cursor on the red line and hit Alt + Enter, it should bring up a menu that one of the options should be to import the class.
michaelconnolly
848 PointsI was reading another post from someone and they said you can't declare a non primitive data type on the same line that it is initialized but I didn't hear that in the video. Is that what it could be? Thanks.
James Simshaw
28,738 PointsThat shouldn't be a problem. We declare non primative variables all of the time and initialize them on the same line. For example:
String website = "teamtreehouse.com";
Declares and initializes a String(which is not a primiative data type in Java) and will work perfectly fine.
michaelconnolly
848 PointsOk I will look over your suggestions tonigh . Thanks for your help. I'll let you know if I got it working. Thanks.
michaelconnolly
848 PointsGoing back to what you said about puttig your cursor on the red line and hit Alt + Enter, it should bring up a menu that one of the options should be to import the class.there was no option for that. Would you know why tha. Is also?
James Simshaw
28,738 PointsNot sure why that isn't working, but you can always add the import statements manually like I showed above. If that doesn't fix everything, we can try further troubleshooting.
michaelconnolly
848 PointsThanks. I'll work on it tonight and let you know.
michaelconnolly
848 PointsOK James. It was the importing. I did have to add it in myself. But it works. Thanks for your help.
James Simshaw
28,738 PointsYou're welcome. Good luck with Android development.
michaelconnolly
848 PointsSorry to bother you again. I did my onclicklistener object. At what point will my button click? I know there's no acting to go to next, (I think that is in the next one or two videos) But I thought the button should at least click and do nothing by now. Any thoughts? Thanks
James Simshaw
28,738 PointsWith the default behavior that we have for this project, the button will never have a down position. However, by the end of the course, there will be press and release action that happens.
michaelconnolly
848 PointsOK I'll keep on going. Thanks for all your help.
michaelconnolly
848 Pointsmichaelconnolly
848 PointsYes I can see the button. But when I declare the Textview and button variables and cast it, the variables are red text, no squiggly line just red text and go to compile it, it comes back with errors saying it can't find symbols for class textview and class button. I had deleted the 2 variables out and did it again and again but get the same errors. I have watched the videos many times and can't seem to see what I'm doing wrong. (I'm sorry if some of this doesn't make since, I'm not at my computer right now and trying to remember the errors it said) thanks for any help.