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

Masum Bergmann
PLUS
Masum Bergmann
Courses Plus Student 4,129 Points

Same code, different models, different screens...

Hi all!!

When I changed my theme to Theme.Black.NoTitleBar.Fullscreen my app actually crashed during the loading process. As per the Teacher's Notes I changed a couple of lines of code, and I was back in business.

After finishing the Crystall Ball app, I installed it on all the android devices I could get my hands on (Samsung Galaxy S2, S4, S5, and Tab10.1), and I noticed something peculiar with the S2, and was wondering if someone could explain it to me... Check out the screenshot below:

Galaxy S5:

S5

On the S5 the app looks as expected!

Galaxy S2:

S2

On the S2 you can see a white bar (titlebar?) across the top of the screen. Why doesn't it appear on the S5? How can I remove the bar completely so it won't even appear on the S2?

Both phones are running the same app. and when I tried running the app after changing the theme to NoTitleBar, it crashed on ALL devices! o.O

I suppose my main question is, what can I do so the white bar won't appear on the S2?

Thanks,

Masum

11 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Oh, I thought it was showing up on newer APIs. Got it backwards. For the older stuff, I think if you change MainActivity to extend a regular Activity instead of ActionBarActivity it might work. Let me know, and if you still have trouble I'll dig deeper on my end.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I am sorry about this. These issues are all related to how the tools now create new projects. This will all be addressed with a refresh of this project, which I'm just starting now.

What's happening here is that the new "appcompat" tools and styles are causing issues. The appcompat is for backwards compatibility for the Action Bar and other newer elements, but as you can see it causes some headaches!

Try this and let me know how it goes for you. Open up the file res > values-v11 > styles.xml and paste in the code below over what's currently in there. We're adding the line about windowActionBar:

<resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!-- API 11 theme customizations can go here. -->
        <item name="android:windowActionBar">false</item>
    </style>

</resources>

This is a style that only gets applied to API version 11 and up (that's why the -11 appears in the folder name). I think this might fix your issue.

Masum Bergmann
Masum Bergmann
Courses Plus Student 4,129 Points

Thanks Ben, unfortunately it didn't work. But since the unwated TitleBar actually only appears on my S2 (2.3.5 - API 10) and not on any of my other "higher" API devices, shouldn't we add similar code to the values folder, so it'll apply to all "low" API devices?

I already tried adding the above line, but since it's only valid for API 11+ it didn't work.

Masum Bergmann
PLUS
Masum Bergmann
Courses Plus Student 4,129 Points

Ben, you hit the nail on the head... what I'm trying to say is that it worked! :D Thank you for your continued assistance!

Nicholas Enslow
Nicholas Enslow
242 Points

This part is hanging me up. Think I need to get into some other coding things rather then jumping right into app development.

Masum Bergmann
Masum Bergmann
Courses Plus Student 4,129 Points

Hi Nicholas, android app development is unlike any other programing that I have done before, and it sure helps to understand the basic concepts of Object-Oriented-Programing before starting developing android applications. Having said that, I must also say that it's awesome fun, and that (at this point in time) it's my favourite way to roll... erm, I mean to program! ;-)

So don't get discouraged, you will always run into things that you may not understand at first, but figuring them out is part of the fun! And you can always ask questions here in the forum! :D

If you want to try your hand at something else first, before returning to android app development, I can definitely recommend javascript. Although java is to javascript, as car is to carpet, It will teach you the basic concepts behind OOP, it's easy enough to pick up, and it's a pretty usefull tool to have in your tool-belt.

Good Luck!

So I think I finally fixed it, There was a missing > on line one and that seemed to resolve the issue, Still having warnings about missing attributes on lines 2, 6 and 25.. I got them to go away earlier then they came back for some reason. The warning says for line one is "Unexpected text found in layout file: "android:layout_width="match_parent" android:layout_height="match_parent" android:background="@an..."

Line 2 is "[Accessibility] Missing contentDescription attribute on image"

Line 25 is [I18N] Hardcoded string "Enlighten me!", should use @string resource

But this is what I have for that section

When I try to launch the app it still crashes because of an unexpected Error. I've been working on this for so long its starting to disappoint me and kinda kick me in the stomach making me feel like I'm not able to write java. I'm new to this and I'm not really sure what else to do at this point, that seems to be the only area I'm having an issue with, everything else looks good at this point from what I can tell, no warnings or Errors on any other pages. please help!!

<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:background="@android:color/black" >

<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_centerInParent="true"
 android:layout_marginLeft="65dp"
 android:layout_marginTop="135dp"
 android:textSize="32sp"/>

<Button android:id="@+id/button1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:text="Enlighten me!"/>

</RelativeLayout>
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry for your trouble! I have a new version of this course in the works. In the mean time, what error do you get in the logcat or console tab in Eclipse when you run your app?

Hey Ben,

Thanks for getting back and letting me know there's a new version in the works, I really want to get this knocked out so I can keep going with the courses, I don't want to keep going if I feel like I can't accomplish this task. This is what I'm getting from the logcat Error wise when I try to launch the app

07-28 17:51:27.141: D/AndroidRuntime(1063): Shutting down VM 
07-28 17:51:27.141: W/dalvikvm(1063): threadid=1: thread exiting with uncaught exception (group=0xb1ac0ba8) 
07-28 17:51:27.151: E/AndroidRuntime(1063): FATAL EXCEPTION: main 
07-28 17:51:27.151: E/AndroidRuntime(1063): Process: com.example.crystalball, PID: 1063 
07-28 17:51:27.151: E/AndroidRuntime(1063): 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. 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.ActivityThread.access$800(ActivityThread.java:135) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.os.Handler.dispatchMessage(Handler.java:102) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.os.Looper.loop(Looper.java:136) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.ActivityThread.main(ActivityThread.java:5017) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at java.lang.reflect.Method.invokeNative(Native Method) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at java.lang.reflect.Method.invoke(Method.java:515) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at dalvik.system.NativeStart.main(Native Method) 
07-28 17:51:27.151: E/AndroidRuntime(1063): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 07-28 17:51:27.151: E/AndroidRuntime(1063): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at com.example.crystalball.MainActivity.onCreate(MainActivity.java:17) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.Activity.performCreate(Activity.java:5231) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
07-28 17:51:27.151: E/AndroidRuntime(1063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
07-28 17:51:27.151: E/AndroidRuntime(1063): ... 11 more
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Okay, we'll get you there! Line 5 has the relevant error:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

This is related to the same bug that I address in the Teacher Notes. Have you walked through those steps yet? You need to change the theme to a new version in the AndroidManifest.xml file. Give those instructions a shot and let me know if you have further trouble.

Well on the bright side its working again! Thanks for your help, I've seriously been stuck on this since Friday, Down side.. all the text is dark so that's something I'll have to look at and I'm still getting warnings but hey its working now!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Cool! Changing the text color is pretty easy in the Graphical Editor or in XML, but post a new question if you have any trouble with it. :)

Old Man
Old Man
1,333 Points

i am having trouble figuring out what "4) Change MainActivity to extend Activity, not ActionBarActivity" even refers to? i think i got the first 3 steps right but i don't even know where to begin with this one.

Hey Jon!

If I remember correctly on the left hand side you'll go from, CrystalBall>Layout>"Activity_main_list.xml", Double click in>Graphical view>on the right hand side you'll see the relative layout info, and in there you should be able to change it there.

I'm not 100% sure any more because I had to reformat my HDD and lost the application and everything but I think in that general area is where you would want to go to look for that. I hope this works!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry! This will all be better in the new version of the course due in 1-2 weeks. But in the mean time, you need to change this line:

public class MainActivity extends ActionBarActivity {

to this:

public class MainActivity extends Activity {
Old Man
Old Man
1,333 Points

got it. thank you both.

Nathan Anderson-Tennant
Nathan Anderson-Tennant
2,160 Points

Hi, I'm running this on a Samsung Galaxy S2 (4.2.2) and cannot seem to get rid of the the titlebar/actionbar. Mine still shows as the example above even after using the fix Ben provided for the styles.xml files

It's unfortunate because i can only use my phone for debugging.

Nathan Anderson-Tennant
Nathan Anderson-Tennant
2,160 Points

Update: This is what worked for me. For some reason, its not picking this up from the parent style. Ensure the code is in "AppTheme" rather than just "AppBaseTheme"

<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.
        -->
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>

    </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>
        <item name="android:windowFullscreen">true</item>
    </style>

</resources>
Eric Uys
PLUS
Eric Uys
Courses Plus Student 807 Points

Ben- I did what you said but got errors all over the place.

http://imgur.com/yQNzpzq

Joshua Scott
Joshua Scott
540 Points

I got the same exact errors as Eric, as well. Was I supposed to change it in the MainActivity.java? Sorry it's my very first time doing android or java.

Joshua Scott
Joshua Scott
540 Points

Also I'm planning to run my app on the lg g3 phone so should I put the image file into hdpi or is mdpi good enough?

Joshua Scott
Joshua Scott
540 Points

I found what worked for me is not changing anything in MainActivity.java file so that it reads as the following:

public class MainActivity extends ActionBarActivity {

private CrystalBall mCrystalBall = new CrystalBall();

ALSO, I made sure to input the following two lines into the mentioned res/layout/styles.xml file:

style name="AppTheme" parent="AppBaseTheme"

item name="android:windowNoTitle">true</item

item name="android:windowFullscreen">true</item

Make sure to add all proper punctuation (ie: <, >, ;)

Eric Uys
Eric Uys
Courses Plus Student 807 Points

Thanks. I'll give this a try. Hope it works!

Eric Uys
Eric Uys
Courses Plus Student 807 Points

Just tried everything you suggested. I'm still getting a message in the emulator that says, "Unfortunately, Crystal Ball has stopped."