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 trialLeonel Saldivar
459 PointsCannot resolve symbol 'showFactButton'
Hi, I have the error "Cannot resolve symbol 'showFactButton'. I've tried with the answers here at the community but couldn't fix it.
This is the java code:
package com.example.usuario.funfacts;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// Declarar variables
private TextView mFactTextView;
private Button mShowFactButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Asignar las vistas del layout file al corresponding variables
mFactTextView = (TextView) findViewById(R.id.factortextView);
mShowFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//the button was clicked so update with a new fact
String fact = "los perros son bien rapidos";
mFactTextView.setText(fact);
}
};
mShowFactButton.setOnClickListener(listener);
}
}
And this is the xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.usuario.funfacts.MainActivity" android:background="#39add1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Che, sabías que...?"
android:id="@+id/textView2"
android:textSize="24dp"
android:textColor="#80ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="es un mundo muy extraño?"
android:id="@+id/factortextView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="24sp"
android:textColor="#ffffff" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="¡Contame más guachín!"
android:id="@+id/factorbutton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/white" />
</RelativeLayout>
I hope someone can help me out. Best regards,
1 Answer
Seth Kroger
56,413 PointsThe id of your button in the XML is "factorbutton" but in the Java code you're using "showFactButton". You should only use one or the other, and make both of them the same name.
Leonel Saldivar
459 PointsLeonel Saldivar
459 PointsThank you!! It worked perfectly. Best