0

好的,这里是 XML 代码 http://i.imgur.com/PnhxAOB.png

叹息我已经尝试解决这个问题超过一个小时我不知道发生了什么..我在最后一行代码中得到错误: ph0ne= (EditText) findViewById(R.id.testphone);

public class MyActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        btn1= (Button) findViewById(R.id.buttonGoTonumber);
        btn2= (Button)  findViewById(R.id.test3button);
        layHome = (LinearLayout) findViewById(R.id.layHomeddddddd);
        layAddNumer = (LinearLayout) findViewById(R.id.test3LAY);
        ph0ne= (EditText) findViewById(R.id.testphone);
    }
}

编辑:由于某种原因,我无法添加 XML 代码。这是 stackTrace:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spiratessgmail.myapplication/com.spiratessgmail.myapplication.MyActivity}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.EditText
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.EditText
            at com.spiratessgmail.myapplication.MyActivity.onCreate(MyActivity.java:33)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

1
android.widget.LinearLayout cannot be cast to android.widget.EditText

意味着你应该改变

 ph0ne= (EditText) findViewById(R.id.testphone);

ph0ne= (LinearLayout) findViewById(R.id.testphone);

或者如果您的 View 应该是 a EditText,您必须在 a 中使用 id testphone (即 a LinearLayout)更改视图EditText

于 2014-10-10T18:30:01.167 回答
0

我认为您只是在引用您的设计 id 时犯了一个错误,请检查您EditText的 id,因为正如您在错误日志中看到的那样,此 idR.id.testphone指的是 a LinearLayout,只需edit-text在您的 XML 中检查您的 id

于 2014-10-10T18:34:44.467 回答