0

我正在设计我的第一个 android 应用程序并不断出现以下错误,这正在耗尽我的生命,我不太了解它(请找到我的 Logcat(详细),Java 代码(我玩过这个,这开始了一旦开始在我的editButton和buttonUpdate位上工作就会发生。它与editStatus有什么关系吗?我真的认为它可能)并且我还放入了我的清单文件:

LOGCAT 详细

04-21 15:30:23.388: D/AndroidRuntime(276): Shutting down VM
04-21 15:30:23.388: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-21 15:30:23.427: E/AndroidRuntime(276): FATAL EXCEPTION: main
04-21 15:30:23.427: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.locator.demo/com.locator.demo.LocatorDemoActivity}: java.lang.ClassCastException: android.widget.TextView
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.os.Looper.loop(Looper.java:123)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-21 15:30:23.427: E/AndroidRuntime(276):  at java.lang.reflect.Method.invokeNative(Native Method)
04-21 15:30:23.427: E/AndroidRuntime(276):  at java.lang.reflect.Method.invoke(Method.java:521)
04-21 15:30:23.427: E/AndroidRuntime(276):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-21 15:30:23.427: E/AndroidRuntime(276):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-21 15:30:23.427: E/AndroidRuntime(276):  at dalvik.system.NativeStart.main(Native Method)
04-21 15:30:23.427: E/AndroidRuntime(276): Caused by: java.lang.ClassCastException: android.widget.TextView
04-21 15:30:23.427: E/AndroidRuntime(276):  at com.locator.demo.LocatorDemoActivity.onCreate(LocatorDemoActivity.java:21)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-21 15:30:23.427: E/AndroidRuntime(276):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-21 15:30:23.427: E/AndroidRuntime(276):  ... 11 more
04-21 15:35:23.607: I/Process(276): Sending signal. PID: 276 SIG: 9
04-21 15:50:32.127: D/AndroidRuntime(301): Shutting down VM
04-21 15:50:32.127: W/dalvikvm(301): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-21 15:50:32.147: E/AndroidRuntime(301): FATAL EXCEPTION: main
04-21 15:50:32.147: E/AndroidRuntime(301): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.locator.demo/com.locator.demo.LocatorDemoActivity}: java.lang.ClassCastException: android.widget.TextView
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.os.Looper.loop(Looper.java:123)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-21 15:50:32.147: E/AndroidRuntime(301):  at java.lang.reflect.Method.invokeNative(Native Method)
04-21 15:50:32.147: E/AndroidRuntime(301):  at java.lang.reflect.Method.invoke(Method.java:521)
04-21 15:50:32.147: E/AndroidRuntime(301):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-21 15:50:32.147: E/AndroidRuntime(301):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-21 15:50:32.147: E/AndroidRuntime(301):  at dalvik.system.NativeStart.main(Native Method)
04-21 15:50:32.147: E/AndroidRuntime(301): Caused by: java.lang.ClassCastException: android.widget.TextView
04-21 15:50:32.147: E/AndroidRuntime(301):  at com.locator.demo.LocatorDemoActivity.onCreate(LocatorDemoActivity.java:21)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-21 15:50:32.147: E/AndroidRuntime(301):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-21 15:50:32.147: E/AndroidRuntime(301):  ... 11 more

代码:

package com.locator.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class LocatorDemoActivity extends Activity implements OnClickListener {
    EditText editStatus;
    Button buttonUpdate;

     /** Called when the activity is first created. */
     @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.locationstatus); 

        editStatus = (EditText)findViewById(R.id.edit_status);
        buttonUpdate = (Button)findViewById(R.id.button_update);
        buttonUpdate.setOnClickListener(this);

                //have button 'listen' for click

    }

    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

}

安卓清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.locator.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_main" >
        <activity
            android:name=".LocatorDemoActivity"
            android:label="@string/app_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

我有;

尝试执行 adb kill-server 和 adb start-server 并按照另一篇文章中的建议在没有模拟器的情况下运行它。请稍微理解一下,因为我对 eclipse 和 Java 的了解非常低,而且我正在学习。

请帮忙

4

1 回答 1

0

从这个错误中可以看出:

java.lang.RuntimeException:无法启动活动 ComponentInfo{com.locator.demo/com.locator.demo.LocatorDemoActivity}:java.lang.ClassCastException:android.widget.TextView

和这个:

引起:java.lang.ClassCastException:android.widget.TextView

您正在尝试将 aTextView转换为EditText(在此行中:)editStatus = (EditText)findViewById(R.id.edit_status);

转到locationstatus.xml,然后TextView将 id更改edit_statusEditText.

于 2012-04-21T16:16:15.663 回答