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

Android Build a Simple Android App (retired 2014) Pretty Little Things Adding Sounds

Joshua Scott
Joshua Scott
540 Points

For last video tutorial "Adding Sounds" I receive Error for playSound(); under Main Activity

Please see my details below. On the following script part I get a red X next to where it says "playSound();".

@Override public void onClick(View v) { String answer = mCrystalBall.getAnAnswer();

            // Update the label with our dynamic answer
            mAnswerLabel.setText(answer);

            animateCrystalBall();
            animateAnswer();
error here  >>> playSound();

        }
    });
}

package com.example.crystalball;

import android.graphics.drawable.AnimationDrawable; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.animation.AlphaAnimation; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

private CrystalBall mCrystalBall = new CrystalBall();
private TextView mAnswerLabel;
private Button mGetAnswerButton;
private ImageView mCrystalBallImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Assign the the Views from the layout file
    mAnswerLabel = (TextView) findViewById(R.id.textView1);
    mGetAnswerButton = (Button) findViewById(R.id.button1);
    mCrystalBallImage = (ImageView) findViewById(R.id.imageView1);

    mGetAnswerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String answer = mCrystalBall.getAnAnswer();

            // Update the label with our dynamic answer
            mAnswerLabel.setText(answer);

            animateCrystalBall();
            animateAnswer();
            playSound();

        }
    });
}

private void animateCrystalBall() {
    mCrystalBallImage.setImageResource(R.drawable.ball_animation);
    AnimationDrawable ballAnimation = (AnimationDrawable) mCrystalBallImage.getDrawable();
    if (ballAnimation.isRunning()) {
        ballAnimation.stop();
    }
    ballAnimation.start();
}

private void animateAnswer() {
    AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
    fadeInAnimation.setDuration(1500);
    fadeInAnimation.setFillAfter(true);

    mAnswerLabel.setAnimation(fadeInAnimation);
}

private void playsound() {
    MediaPlayer player = MediaPlayer.create(this, R.raw.crystal_ball);
    player.start();
    player.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            mp.release();
        }
    });
}

@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;
}

@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);
}

}

3 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey Joshua! I retired this course today but just wanted to drop a note in here in case you haven't finished it yet. You can still access the stages and videos with direct links, but let me know if you have any trouble. Meanwhile, I'd highly recommend checking out the new version and the rest of the courses on the latest Android track. Cheers!

Joshua Scott
Joshua Scott
540 Points

Hey Ben thanks for reaching out! I was actually able to figure out how to get the application made and put onto my old Google nexus device. I'm now just trying to get it on the app store! Thanks for making this course it taught me so much! I have made my first app!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Excellent! I also released a new short course today called Publish an Android App that has updated info about Google Play.

Joshua Scott
Joshua Scott
540 Points

Is it possible I could get the link from the last course on publishing the crystal ball app to the play store? I didn't get a chance to finish that part.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sure thing! You can walk through it using the arrows with this link to the first video, and here are the rest of the links for that last stage:

Java is a case-sensitive language. You've implemented your method as playsound() and then tried to call it as playSound(). Capitalize the "s" in the method implementation and it should work. If you continue to have issues, let me know.

Joshua Scott
Joshua Scott
540 Points

Dude! Thank you!

You're welcome Joshua, glad I could help!