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 trialMUZ140881 Munyaradzi Dhodho
1,326 Pointserror on my android studio but did not put the codes
Hie am getting the errors below am not sure where this is from
Error:(55, 13) error: class, interface, or enum expected Error:(58, 5) error: class, interface, or enum expected Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
2 Answers
Steve Hunter
57,712 PointsHi there,
I don't know what you're trying to do here, however, there's good code in there that seems to be related to the part of your code you have a problem with. This is perfect, assuming the button is called showFactButton
in your xml:
Button showFactButton = (Button) findViewById(R.id.showFactButton);
However, this isn't quite correct:
@Override
private View findViewById(int showFactButton) {
return null;
}
If you can let me know what you want this to do, I can help you out.
Is this a code challenge as part of one of the tracks? If so, let me know which one and I'll try to walk you through the solution you need.
Steve.
Steve Hunter
57,712 PointsCan you post the files you have written code in? I think you'll just have one, FunFactsActivity
- let's have a look at the code in there.
Thanks.
Steve.
MUZ140881 Munyaradzi Dhodho
1,326 Points@Override
private View findViewById(int showFactButton) {
return null;
}
}
Steve Hunter
57,712 PointsCan you post the whole file, please?
Steve.
MUZ140881 Munyaradzi Dhodho
1,326 Pointspackage com.example.msfuser.funfacts;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FunFactsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
// Declare our View variables and assign them views from the layout file
final 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 view) {
// The button was clicked, so update the fact label with a new fact
String fact = "";
// Randomly select a fact
Random randomGenerator = new Random (); // Construct number generator
int randomNumber = randomGenerator.nextInt(3);
fact = randomNumber + "";
// Update the label with our dynamic fact
factlabel.setText(fact);
}
};
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.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
@Override
private View findViewById(int showFactButton) {
return null;
}
}
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI found the challenge and you've done it! The first line of code above is all you need to do. So just have:
Button showFactButton = (Button) findViewById(R.id.showFactButton);
in the place indicated completes the challenge. The other bit you've added can be deleted.
Hope that helps.
Steve.