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 an Image

Crystal Ball Background

Hey guys, I've run through it 3 times and can't get the background to appear when I run the app. Any idea what I should look out for? I must be missing something. Thanks!

5 Answers

Good morning Christopher, could you post the code that you have so far? Without seeing the code I would wager that you have a simple syntax error or that your image file is not in correct folder.

Nope. I had to restart my pc this morning so I restarted eclipse and the "phone" and when I did it was on there as a background when using the app. shrug,, Sometimes a simple restart is all things need I guess

Hi adam, My image file is in drawable-mdpi. Here is my code.. CrystalBall.java package com.example.crystalball;

import java.util.Random;

public class CrystalBall { // Member variables (properties about the object) String[] mAnswers = { "It is certain", "It is decidely so", "All signs say YES", "The stars are not aligned", "My reply is no", "It is doubtful", "Better not tell you now", "Concentrate and ask again", "Unable to answer now", "It is hard to say" };

// Methods )abilities: things the object can do)
public String getAnAnswer() {

            String answer = "";

    //Randomly select one of three answers: Yes, No, or Maybe
    Random randomGenerator = new Random(); //Construct a new Random number generator 
    int randomNumber = randomGenerator.nextInt(mAnswers.length);


    answer = mAnswers[randomNumber];

    return answer;
}

}

CrystalBall Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.crystalball" android:versionCode="1" android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Main Activity

package com.example.crystalball;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; 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);

    // Delcare our view variables and assign them the Views from the layout file
    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 arg0) {
            String answer = mCrystalBall.getAnAnswer();


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


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

}

Let me know if you need to see something else. I'll keep working on it as well.

Thank you!

Actually, today it works!! Thank you Adam

Well, I'm glad I could...offer to help :) did you find out what the glitch was?