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 trialAdama Sy
7,076 PointsCan you see the syntax error and how to fix it? thanks
package com.example.crystal.ball;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare our view variables
TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton= (Button) findButtonById(R.id.Button);
}
8 Answers
Cristian Rivera
2,192 PointsOh , vaya error !
//Tu Error - Button getAnswerButton= (Button) findButtonById(R.id.Button);
//Respuesta - Button getAnswerButton= (Button)findViewById(R.id.Button);
- Ademas , ten en cuenta de que un "id" no tiene que empezar con "MAYUSCULAS" - "R.id.Button" esta mal , lo mas seguro es que sea asi "R.id.button"
Saludos
Cristian Rivera
2,192 PointsBen Jakuben
Treehouse TeacherTwo things jump out:
1) A closing curly brace is missing at the bottom of the code you pasted. That could just be a copy/paste error in here, but wanted to point it out.
2) You are using the ID R.id.Button
, but the ID you are supposed to use is R.id.button1
. Note the lowercase "b" (case matters!) and the "1" at the end.
Hope this helps!
Adama Sy
7,076 PointsI made it all in lower case. its not working still checked all the curly brace, restarted all by scratch I get this
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare our view variables
TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewbyId(R.id.button1);
}
}
and when I check the error this is what I get:
./com/example/crystal/ball/MainActivity.java:18: cannot find symbol symbol : method findViewbyId(int) location: class com.example.crystal.ball.MainActivity Button getAnswerButton = (Button) findViewbyId(R.id.button1); ^ 1 error
But this is what some student wrote and passed the challenge for me it's just not working
Ben Jakuben
Treehouse TeacherCan you paste in all the code you are trying? It looks like there is some small typographical error somewhere causing these compiler errors, but we'll need all your code to troubleshoot it.
John Carr
Courses Plus Student 1,984 PointsR.id.textView1?
Adama Sy
7,076 Pointsthat is not wrong, it's what the first course says, that is what the teacher wrote, now I' looking at writing the button code. it says I have one error. Java is so weird and harder to understand.
John Carr
Courses Plus Student 1,984 Pointsdid you run debugger and find which line your are getting the error?
Adama Sy
7,076 PointsError is on the last line yes. But I don't know what they mean when I read it. Honestly I find Android course not well explained. we go from part A to X then back to E in a very short period of time. Could be explained in a better way.
John Carr
Courses Plus Student 1,984 PointsMaybe if you show here what the error says and the line its on maybe people can help.
Adama Sy
7,076 Points./com/example/crystal/ball/MainActivity.java:18: ';' expected Button getAnswerButton= (Button) findViewById(R.id.button1) ^ 1 error
Adama Sy
7,076 PointsAdama Sy
7,076 Points¡Hola Hice lo que me dijiste. Y este es el error que se incluye. ¿Y ahora qué? . / com / ejemplo / de cristal / de bola / MainActivity.java: 18: cannot find symbol sÃmbolo: Botón variables ubicación: Clase com.example.crystal.ball.R.id         Botón getAnswerButton = (Button) findViewById (R.id.Button);                                                              ^ 1 error
Cristian Rivera
2,192 PointsCristian Rivera
2,192 PointsHola .
Es que no te diste cuenta de tu error aun , te lo explico mejor . un "ID" creado en la vista "xml" nunca debe tener un caracter en "MAYUSCULA" , en el pedazo de código que me enviaste figura lo siguiente
Saludos Adama !