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 trialEleni Minadaki
3,687 PointsProblem on lesson Making Button do Something
Hi!i have write the code of this lesson,but there are 3 errors which i can't solve. on the lines of code: 1) TextView factLabel = (TextView) findViewById(R.id.factTextView); 2)ButtonshowFactButton= (Button)findViewById(R.id.showFactButton); errors:1)cannot resolve symbol'factTextView' 2)cannot resolve symbol'showFactLabel 3)Variable'factLabel is never used''
I think the problem begin from somewhere else here is all my code:
package com.teamtreehouse.funfacts;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
public class FunFactsActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
//Declare our vew variables and assign the Views from the layout file.
TextView factLabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton=(Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
}
};
showFactButton.setOnClickListener(listener);
}
@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_fan_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);
}
}
Appreciate any help!
2 Answers
Emil Johansen
5,107 Points1) The problem is your reference to the id of the TextView: R.id.factTextView
Either you misspelled it (it's not called factTextView
), or you misnamed it in your activity_funfacts.xml
layout file :) Check that they match! Autocomplete can help you to see which ID's are available when you type R.id.
then a list of id's should show up.
If you are using Android Studio, it should mark the place in the code that is causing trouble for you as red. If you put your cursor on it, there should appear a popup with suggestion of how to fix it :)
2) same as 1)
3) It is not an error, just a warning for you. It appears because you are not using the factLabel
variable for anything :) It doesn't appear anywhere in your code, other than the place where you are defining it: TextView factLabel = (TextView) findViewById(R.id.factTextView);
. I assume you are still in the middle of the course. Later when you assign it some functionality, the warning will disappear.
Eleni Minadaki
3,687 PointsHi Emil, thanks a lot for your help! You was right,i went in activity_funfacts.xml layout file and i find 1) android:id="@+id/ShowFactButton" 2) android:id="@+id/fun_facts", so went back to FunFactsActivity.java and wrote: 1)TextView factLabel = (TextView) findViewById(R.id.fun_facts); 2) Button showFactButton=(Button) findViewById(R.id.ShowFactButton); Now there is no errors,hope to make the right. Thanks again!