JonSkeet 2013-03-19 08:38 采纳率: 0%
浏览 2165
已采纳

表格行中的 Relative layout 布局

我在表格行中设置了相对布局,当运行下面的代码时出现 Logcat:错误,如何处理这个问题?

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

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

  • 写回答

3条回答

  • nana4ever 2013-03-25 06:17
    关注

    以前我也遇见过这个错误,由于不同的 View,在有 GridView 的地方,会扰乱一个 ProgressBar。应该清除你的项目。
    Project-->Clean...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog