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

Ben Junya
Ben Junya
12,365 Points

App Crashes when follow all instructions in video

Is there an update to this module? My application keeps on crashing whenever I try to run it after following the instructions in this module.

I added the image just like what was said in the video, but the application crashes upon start. What's happening?

Ben Junya
Ben Junya
12,365 Points

Here is a copy of the crash log from the Console:

04-06 23:25:43.510: E/AndroidRuntime(975): FATAL EXCEPTION: main 04-06 23:25:43.510: E/AndroidRuntime(975): Process: com.example.crystalball, PID: 975 04-06 23:25:43.510: E/AndroidRuntime(975): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crystalball/com.example.crystalball.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.ActivityThread.access$800(ActivityThread.java:135) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.os.Handler.dispatchMessage(Handler.java:102) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.os.Looper.loop(Looper.java:136) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.ActivityThread.main(ActivityThread.java:5017) 04-06 23:25:43.510: E/AndroidRuntime(975): at java.lang.reflect.Method.invokeNative(Native Method) 04-06 23:25:43.510: E/AndroidRuntime(975): at java.lang.reflect.Method.invoke(Method.java:515) 04-06 23:25:43.510: E/AndroidRuntime(975): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 04-06 23:25:43.510: E/AndroidRuntime(975): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 04-06 23:25:43.510: E/AndroidRuntime(975): at dalvik.system.NativeStart.main(Native Method) 04-06 23:25:43.510: E/AndroidRuntime(975): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 04-06 23:25:43.510: E/AndroidRuntime(975): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98) 04-06 23:25:43.510: E/AndroidRuntime(975): at com.example.crystalball.MainActivity.onCreate(MainActivity.java:16) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.Activity.performCreate(Activity.java:5231) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 04-06 23:25:43.510: E/AndroidRuntime(975): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 04-06 23:25:43.510: E/AndroidRuntime(975): ... 11 more

Ben Junya
Ben Junya
12,365 Points

Here's what I THINK is happening:

In the error log, there's this: You need to use a Theme.AppCompat theme (or descendant) with this activity.

I went back into the CrystalBall Manifest > Application tab

Then clicked on Theme > Browse - there's 2 radial buttons - Project Resources and System Resources

Any theme from "Project Resources" works fine and the app doesn't crash

The theme used in the video, "Theme.black.NoTitleBar.Fullscreen" is in the System resources. I think this is why the application is crashing upon running.

Is there a fix around this? The themes in Project Resources all make the Crystal Ball app look terrible!

4 Answers

Can you please provide a sample of your code ?

Ben Junya
Ben Junya
12,365 Points

Here's AndroidManifest.xml <?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="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>

Ben Junya
Ben Junya
12,365 Points

And here's activity_main.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" 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" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:gravity="center_horizontal"
    android:shadowColor="@android:color/white"
    android:shadowRadius="10"
    android:textColorLink="@android:color/white"
    android:textSize="32sp" />

<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" />

</RelativeLayout>

Ben Junya
Ben Junya
12,365 Points

I think it may have something to do with the image itself. There's no errors on the console, but there's 2 warnings (Hardcoded string and imagedescription). Anything I can do to fix this?