Why does my program crash after I add Listview? Android
I am attempting to connect a listview lv to its id using
ListView lv = (ListView) findViewById(R.id.ImTrackingListView);
However whenever it hits this step my program crashes and sends it to the Source not found page. Here is my code
public class ImTracking extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.imtrackinglayout);
ListView lv = (ListView) findViewById(R.id.imtrackinglistview);
I checked to make sure that there wasn't another id with the same name. Hopefully someone can help me find out why this is happening.
edit here is the xml (I changed the id to lowercase)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/imtrackinglistview"></ListView>
</LinearLayout>
Here is my logcat response
08-09 20:19:12.335: WARN/System.err(640): java.lang.ClassCastException: android.widget.TextView
08-09 20:19:12.354: WARN/System.err(640): at com.cellphone.ImTracking.onCreate(ImTracking.java:30)
08-09 20:19:12.366: WARN/System.err(640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-09 20:19:12.366: WARN/System.err(640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
08-09 20:19:12.374: WARN/System.err(640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
08-09 20:19:12.374: WARN/System.err(640): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-09 20:19:12.374: WARN/System.err(640): at android.app.ActivityThread$H.handleMessag开发者_运维问答e(ActivityThread.java:928)
08-09 20:19:12.384: WARN/System.err(640): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 20:19:12.384: WARN/System.err(640): at android.os.Looper.loop(Looper.java:123)
08-09 20:19:12.394: WARN/System.err(640): at android.app.ActivityThread.main(ActivityThread.java:3647)
08-09 20:19:12.394: WARN/System.err(640): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 20:19:12.394: WARN/System.err(640): at java.lang.reflect.Method.invoke(Method.java:507)
08-09 20:19:12.404: WARN/System.err(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-09 20:19:12.404: WARN/System.err(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-09 20:19:12.404: WARN/System.err(640): at dalvik.system.NativeStart.main(Native Method)
08-09 20:19:16.847: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
08-09 20:19:16.987: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{408bf110 com.cellphone/.ImTracking}
Try cleaning your project, for some reason the error contains a TextView
.
There is a class cast exception in ImTracking file , post the error from log cat.Select E - and the last exception thrown would be in red , paste that.
精彩评论