我有以下布局,我认为一切都是正确的,但是在运行这些代码时出现以下错误!有任何想法吗?
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#e3e1e1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/tPr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<GridView
android:id="@+id/tApps"
android:layout_width="wrap_content"
android:layout_height="258dp"
android:background="#e3e1e1"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="3"
android:verticalSpacing="2dp"
android:visibility="gone">
</GridView>
</RelativeLayout>
</TableRow>
</TableLayout>
这是我的Logcat:
02-20 17:34:34.261: E/AndroidRuntime(1125): FATAL EXCEPTION: main
02-20 17:34:34.261: E/AndroidRuntime(1125): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.coverflow/com.example.coverflow.CoverFlowExample}: java.lang.ClassCastException: android.widget.ProgressBar
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.os.Looper.loop(Looper.java:123)
02-20 17:34:34.261: E/AndroidRuntime(1125): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-20 17:34:34.261: E/AndroidRuntime(1125): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 17:34:34.261: E/AndroidRuntime(1125): at java.lang.reflect.Method.invoke(Method.java:521)
02-20 17:34:34.261: E/AndroidRuntime(1125): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-20 17:34:34.261: E/AndroidRuntime(1125): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-20 17:34:34.261: E/AndroidRuntime(1125): at dalvik.system.NativeStart.main(Native Method)
02-20 17:34:34.261: E/AndroidRuntime(1125): Caused by: java.lang.ClassCastException: android.widget.ProgressBar
02-20 17:34:34.261: E/AndroidRuntime(1125): at com.example.coverflow.CoverFlowExample.onCreate(CoverFlowExample.java:41)
第 41 行是 top = (GridView)findViewById(R.id.tApps);