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 trialJack Speake
254 PointsCrystalBall Glitch
When i try and run my app i get the error:
"Unfortunately, CrystalBall has stopped." and the error message is
[2014-04-15 21:13:30 - CrystalBall] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.crystalball/.MainActivity }.
My code for "Main Activity" is this:
package com.example.crystalball;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
private CrystalBall mCrystalBall = new CrystalBall();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//declare view variables
final TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);
getAnswerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String answer = mCrystalBall.getAnAnswer();
answerLabel.setText(answer);
animateCrystalBall();
}
});
}
private void animateCrystalBall(){
ImageView crystalBallImage = (ImageView) findViewById(R.id.imageView1);
crystalBallImage.setImageResource(R.drawable.ball_animation);
AnimationDrawable ballAnimation = (AnimationDrawable) crystalBallImage.getDrawable();
if(ballAnimation.isRunning()){
ballAnimation.stop();
}
ballAnimation.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
1 Answer
Ben Jakuben
Treehouse TeacherJust echoing what Ernest said. If you paste in more information from the logcat tab in Eclipse then hopefully we can help you out. :)
Ernest Grzybowski
Treehouse Project ReviewerErnest Grzybowski
Treehouse Project ReviewerI don't see anything wrong with your code at a quick glance.
Can you post your stack trace (crash log from inside of Eclipse)? It will usually be in red color and span more than just 1 or 2 lines. The easiest thing to do is to copy all of the red output from logcat and post it here.
This video is a bit dated, but it should help. https://www.youtube.com/watch?v=2AHJsRKa_J8
A stack trace is extremely useful when debugging applications. Learn more here: http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors