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 trial
Ziga Klemencic
2,569 PointsI have a problem with the animation.
i have a problem, i have just completed the running an app on the divice chapter, i have noticed that my ballAnimation is not working i have a yelow line warrning at private void animateCrystalBall3(), and i cant repair it, i guees i made some kind of a mistake after i made the animation since it worked finr at the start. Apriciate your help. here's the code:
package com.example.crystalball3;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.crystalball3.ShakeDetector.OnShakeListener;
public class MainActivity extends Activity {
private CrystalBall3 mCrystalBall3 = new CrystalBall3();
private TextView mAnwserLabel;
private ImageView mCrystalBall3Image;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private ShakeDetector mShakeDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAnwserLabel = (TextView) findViewById(R.id.textView1);
mCrystalBall3Image = (ImageView) findViewById(R.id.imageView1);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mShakeDetector = new ShakeDetector(new OnShakeListener() {
@Override
public void onShake() {
handleNewAnwser();
}
});
}
@ Override
public void onResume(){
super.onResume();
mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}
@Override
public void onPause(){
super.onPause();
mSensorManager.unregisterListener(mShakeDetector);
}
private void animateCrystalBall3() {
// TODO Auto-generated method stub
}
private void animateAnwser(){
AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
fadeInAnimation.setDuration(1500);
fadeInAnimation.setFillAfter(true);
mAnwserLabel.setAnimation(fadeInAnimation);
}
private void playSound(){
MediaPlayer player = MediaPlayer.create(MainActivity.this, R.raw.crystal_ball);
player.start();
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
private void animateCrystalBall3(){
mCrystalBall3Image.setImageResource(R.drawable.ball_animation);
AnimationDrawable ballAnimation = (AnimationDrawable) mCrystalBall3Image.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;
}
private void handleNewAnwser() {
String anwser = mCrystalBall3.getAnAnwser();
mAnwserLabel.setText(anwser);
animateCrystalBall3();
animateAnwser();
playSound();
}
}
```
Thanks For you'r time. Žiga :D
2 Answers
Mike Caicedo
6,105 PointsLooks like you have declared animateCrystalBall3 twice... Could that be the problem?
Ziga Klemencic
2,569 PointsYES, thanks that really helped.... it was really noob of me that i didn't notice that.
Thank you again for help. :D:D