简体   繁体   中英

Relative layout in table row

I have the following layout, I think everything is right but I got the following errors when I running these codes! any ideas?

   <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>

Here is my 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)

Line 41 is top = (GridView)findViewById(R.id.tApps);

I have had this error, with different View s, that doesn't make sense because its complaining about a ProgressBar where you have a GridView . Assuming you are declaring your views to what they should be, clean your project. In Eclipse

and it should take care of your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM