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

Adding an image, Build a simple android app ERROR NEED HELP!

Hello, I've followed this tutorial pretty much word for word and everything was working great. Now excuse my terms I use they might not be the most correct, as I am extremely new to javascript and coding in general. So as I said I did everything Ben said and the app looks and works great but I came to a small error when we were supposed to change the theme but I thought it was ok because it had a solution in the teachers notes. The solution didn't work for me, I still get the error inside the emulator that states unfortunately crystal ball has stopped, I even tried installing Gennymotion instead of the really slow default emulator nothing works, Please help me I want to finish this lesson! here is some code

ActivityMain.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@android:color/black"
    tools:context="com.example.crystalball.MainActivity$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter"
        android:src="@drawable/ball01" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Enlighten Me"
        android:textColor="#3F0F7F"
        android:textSize="24sp"
        android:textStyle="bold|italic"
        android:typeface="serif" />

    <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_centerVertical="true"
            android:shadowColor="@android:color/white"
            android:shadowRadius="10"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#3f0f7f"
            android:textSize="32sp" />

</RelativeLayout>

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="8"
    android:targetSdkVersion="19" />

<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="com.example.crystalball.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>

styles.xml

```<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
         <item name="android:windowNoTitle">true</item> <!-- Hides the Action Bar -->
         <item name="android:windowFullscreen">true</item> <!-- Hides the status bar -->
    </style>

</resources>```

Crystalball.java

```package com.example.crystalball;

import java.util.Random;

public class CrystalBall {
    // Member variable (properties about the object)
    public String[] mAnswers = {
            "It is certain",
            "It is decidedly 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();
        int randomNumber = randomGenerator.nextInt(mAnswers.length);

        answer = mAnswers[randomNumber];

        return answer;
    }
}

MainActivity.java

package com.example.crystalball;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {
    private CrystalBall mCrystalBall = new CrystalBall();

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

        // Declare our View variables here
        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;
    }

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


}

ANYTHING WOULD HELP! THANKS

2 Answers

I can't get markdown to work correctly apologies if you can't read it properly spent like 30 minutes trying to fix it

Hi Jordan,

try editing your Crystallball Manifest file, I guess this is the line that needs to be updated:

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

with this one:

android:theme="@style/AppTheme" >

Your app should then be able to run in Fullscreen Mode without crashing, if I didn't miss anything :-)