views:

53

answers:

1

Hi there

I've built the bare bones of my app so far in Eclipse using an adapted version of the LunarLander app provided by Android Developers. I've adjusted bits and pieces and have no errors at all though when I run it in the emulator it keeps saying "the application has stopped unexpectedly" and i have to Force Close.

Is it possible that my main.xml layout file is causing this issue? Mine looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/distractions_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text"  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
</LinearLayout>

but their's looks like:

<com.example.android.lunarlander.LunarView
  android:id="@+id/lunar"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
      android:id="@+id/text"
              android:text="@string/lunar_layout_text_text"
              android:visibility="visible"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:gravity="center_horizontal"
      android:textColor="#88ffffff"
      android:textSize="24sp"/>
 </RelativeLayout>

Could this be responsible for the app being unable to launch? If I need to post my code I will but its over 900 lines so thought I would just see if this was possibly the problem first?

Thanks to all that can enlighten me!

A: 
java.lang.ClassCastException: android.widget.LinearLayout

This kind of error usually happens when you try and get the view object from your activity class and you cast it incorrectly.

Without seeing your activity classes code I can only guess but you may have something like this:

FrameLayout myLayout = (FrameLayout)findViewById(R.id.distractions_layout);

As *distractions_layout* is a LinearLayout and not a FrameLayout you will get that error. The correct way to do it would be like this:

Linearlayout myLayout = (LinearLayout)findViewById(R.id.distractions_layout);
disretrospect