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 Customizing Buttons and Labels

Justin Stevens
Justin Stevens
5,850 Points

Crystal Ball app not working

My Crystal Ball app is not working, but it is not showing any errors or flags. It says "Unfortunately, Crystal Ball has stopped." Has anyone else had this problem? If so, what did you do to fix it.

10 Answers

Also notice how your top level ImageView's layout width and length attributes assign "match_parent" for its' values. Well since you don't have a parent that is probably what is causing your application to crash when it tries to populate your layout. It doesn't have a boundary. Althought I do think that there is always an invisible root level layout group object because I think that an your container can assign "match_parent" and the root level container would ( and I'm just guessing ) would generate it's height and width values as constants from some type of service that android passes in to specify the screen size of the device running the application...

You're missing your schema declaration at the top. You need to encapsulate your instances of View objects inside of atleast one instance of a ViewGroup object. whether that be LinearLayout, RelativeLayout, FrameLayout...whatever you want. It has to encapsulate that stuff. I may be entirely wrong but I don't think you can put instances of View objects before your first opening tag element declaring some type of ViewGroup. The only thing that goes outside of the opening element tag for the container you choose is the xml version and the encdoing though I'm not sure if encoding is optional. Then the first attribute of the container needs to be xmlns:android="http://schemas.android.com/apk/res/android"

Also make sure you fill the screen with your container. Think of it like a canvas to paint on. So when you set the values for the layout width and height attributes use the "fill_content".

Sage Elliott
Sage Elliott
30,003 Points

Do you have the code you could post? Did you program in the fragment.xml file instead of the main activity file? This may have happened due to the IDE update which added a fragment and made it the default xml file. If this was the case you may have to switch the main activity xml file to a relative layout before copying and pasting from your fragment.

Justin Stevens
Justin Stevens
5,850 Points

I'm fairly certain it's something I'm missing. Here's the XML code:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:weightSum="1" >

    <View
        android:id="@+id/view1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0.2" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.6"
        android:gravity="center_horizontal"
        android:shadowColor="@android:color/white"
        android:text="fart"
        android:textColor="@android:color/white"
        android:textSize="28sp" />

    <View
        android:id="@+id/View2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0.2" />

</LinearLayout>

</RelativeLayout>

Justin Stevens
Justin Stevens
5,850 Points

For some reason, I don't think it got all of the code:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:weightSum="1" >

    <View
        android:id="@+id/view1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0.2" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.6"
        android:gravity="center_horizontal"
        android:shadowColor="@android:color/white"
        android:text="fart"
        android:textColor="@android:color/white"
        android:textSize="28sp" />

    <View
        android:id="@+id/View2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0.2" />

</LinearLayout>

</RelativeLayout>

Justin Stevens
Justin Stevens
5,850 Points

Let me try posting it in two parts. part one:

<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.justinstevens.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" />
Justin Stevens
Justin Stevens
5,850 Points

Sorry to post so much, but for some reason, only the code from <ImageView to the </LinearLayout> is displaying, but when I go to edit it, all of the code displays then.

Good luck. Let me know if that doesn't work.

Can we close this question? I think it has been answered because the original poster has acknowledged an answer through the voting system and did not further provide any indication that the problem persisted afterwards.

Justin Stevens
Justin Stevens
5,850 Points

Sorry I didn't respond sooner. I did find a way to make it work. I didn't change the theme from the original setting and just hid the ActionBar in the java code.