0

我已经在这两天了,但无处可去。希望有人可以提供帮助。

日志猫:

07-09 09:39:03.226: D/dalvikvm(13110): GC_CONCURRENT freed 212K, 4% free 8260K/8519K, paused 24ms+7ms, total 106ms
07-09 09:39:04.164: D/AndroidRuntime(13110): Shutting down VM
07-09 09:39:04.164: W/dalvikvm(13110): threadid=1: thread exiting with uncaught exception (group=0x40f58300)
07-09 09:39:04.207: E/AndroidRuntime(13110): FATAL EXCEPTION: main
07-09 09:39:04.207: E/AndroidRuntime(13110): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vamp6x6x6x.dontpressbutton/com.vamp6x6x6x.dontpressbutton.MainActivity}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.os.Looper.loop(Looper.java:137)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.ActivityThread.main(ActivityThread.java:4745)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at java.lang.reflect.Method.invokeNative(Native Method)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at java.lang.reflect.Method.invoke(Method.java:511)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at dalvik.system.NativeStart.main(Native Method)
07-09 09:39:04.207: E/AndroidRuntime(13110): Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
07-09 09:39:04.207: E/AndroidRuntime(13110):    at com.vamp6x6x6x.dontpressbutton.MainActivity.onCreate(MainActivity.java:19)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.Activity.performCreate(Activity.java:5008)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-09 09:39:04.207: E/AndroidRuntime(13110):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
07-09 09:39:04.207: E/AndroidRuntime(13110):    ... 11 more
07-09 09:39:04.476: D/dalvikvm(13110): DexOpt: --- BEGIN 'ads90661078.jar' (bootstrap=0) ---
07-09 09:39:05.207: D/dalvikvm(13110): DexOpt: --- END 'ads90661078.jar' (success) ---
07-09 09:39:05.211: D/dalvikvm(13110): DEX prep '/data/data/com.vamp6x6x6x.dontpressbutton/cache/ads90661078.jar': unzip in 0ms, rewrite 731ms

07-09 09:39:08.820: I/Process(13110): 发送信号。PID:13110 SIG:9

布局xml:

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

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/ic_launcher"
        android:minHeight="230dp"
        android:minWidth="230dp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageButton1"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="18dp"
        android:text="Do not press the button"
        android:textColor="#000000"
        android:textSize="45px"
        android:textStyle="bold" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageButton1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="18dp"
        android:text="Text here"
        android:textColor="#000000"
        android:textSize="30sp" />



</RelativeLayout>

显现:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.vamp6x6x6x.dontpressbutton"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>


    </application>

</manifest>

如果你需要我的 java 我会提供它,但我不确定你是否需要它,因为我不擅长阅读 log cat。

4

1 回答 1

2

正如我们在 logcat 消息中看到的

Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button

这意味着您已经分配了Image Buttonto的引用Button。改变它并做即

ImageButton imgBtn= (ImageButton) findViewById(R.id.imageButton1);
于 2013-07-09T14:10:03.507 回答