Android 应用程序崩溃可能是布局错误。我找不到

Android 应用程序崩溃可能是布局错误。我找不到,android,android-layout,android-view,logcat,Android,Android Layout,Android View,Logcat,我的应用程序正在崩溃,但logcat没有显示任何内容 我认为这是布局中的一些内容,但是当我在java文件上禁用一些findViewById时,布局确实会加载 我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pare

我的应用程序正在崩溃,但logcat没有显示任何内容

我认为这是布局中的一些内容,但是当我在java文件上禁用一些
findViewById
时,布局确实会加载

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ItemView" >

    <Space
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="136dp"
        android:layout_marginTop="205dp" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="191dp"
        android:layout_marginRight="156dp"
        android:text="Item Title"
        android:background="#DCFFFF"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/title"
        android:layout_alignLeft="@+id/title"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/title"
        android:layout_marginLeft="140dp"
        android:background="#d5d4d4"
        android:src="@android:drawable/gallery_thumb" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/title"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/imageView1"
        android:layout_below="@+id/loadaddr"
        android:background="#ADF3F2" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="17dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Item Description" />

            <TextView
                android:id="@+id/pub"
                android:layout_width="123dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp"
                android:text="Publisher" />
        </LinearLayout>
    </ScrollView>

    <ProgressBar
        android:id="@+id/loadimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_marginBottom="94dp"
        android:layout_marginLeft="48dp" />

    <ProgressBar
        android:id="@+id/loadaddr"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/addr"
        android:layout_alignLeft="@+id/loadimg"
        android:layout_marginLeft="15dp" />

    <TextView
        android:id="@+id/addr"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/title"
        android:layout_below="@+id/imageView1"
        android:gravity="center"
        android:text="Fetching Address" />

</RelativeLayout>
在我尝试移动布局上的一些文本视图之前,一切都很好

我移动它们后,它开始破碎。我试着把我搬回来的东西都放回去,但没有用。

改变

ProgressBar Loadaddr;

在我尝试移动布局上的一些文本视图之前,一切都很好

这总是一个清理项目的好时机

“项目-->清理…”


有时Eclipse无法立即识别
布局
更改,您将得到这些毫无意义的错误。从我看到的情况来看,您正在声明它并正确地初始化它,因此当您收到一条错误消息说您正在尝试将一个对象强制转换为另一个对象,而您知道您没有这样做时,请清理项目,Eclipse应该正确地检测到它。这通常发生在更改xml文件后。

“Logcat不显示任何内容”-Logcat始终打印堆栈跟踪。您需要将Eclipse中的Logcat消息过滤为您应用程序中的消息,或者您有一个限制性太强的过滤器。但我确信其中有一个堆栈跟踪将指向崩溃的原因。这是一个非常多的代码。没有Logcat,很难找到问题。在运行应用程序之前,请尝试打开logcat。然后发布日志cater,毕竟它显示了logcat。对不起,我不知道发生了什么,但上次我试过了。那么我的代码有什么问题?我又查了一遍。。TextView和ProgressBar似乎一切正常。检查您的所有TextView和PropressBar ID,存在一些冲突。请告诉我哪一个是第61行?它的
Loadimg=(ProgressBar)findViewById(R.id.Loadimg)但问题已解决。。是的,我只是想清理一下主体。就是这样。这么愚蠢的问题。。对不起,浪费了你的时间。泰,没问题。你没有浪费我的时间。这种情况经常发生。如此之多,以至于如果您搜索ClassCastException,您可能会找到它;)但希望这个解释能对你将来有所帮助。
08-11 19:54:45.437: E/AndroidRuntime(1218): FATAL EXCEPTION: main
08-11 19:54:45.437: E/AndroidRuntime(1218): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.free/com.example.free.ItemView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ProgressBar
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.ActivityThread.access$600(ActivityThread.java:153)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.os.Looper.loop(Looper.java:137)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.ActivityThread.main(ActivityThread.java:5227)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at java.lang.reflect.Method.invokeNative(Native Method)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at java.lang.reflect.Method.invoke(Method.java:511)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at dalvik.system.NativeStart.main(Native Method)
08-11 19:54:45.437: E/AndroidRuntime(1218): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ProgressBar
08-11 19:54:45.437: E/AndroidRuntime(1218):     at com.example.free.ItemView.onCreate(ItemView.java:61)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.Activity.performCreate(Activity.java:5104)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-11 19:54:45.437: E/AndroidRuntime(1218):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
08-11 19:54:45.437: E/AndroidRuntime(1218):     ... 11 more
ProgressBar Loadaddr;
TextView Loadaddr;