確定這裏是XML代碼http://i.imgur.com/PnhxAOB.pngjava.lang.ClassCastException:幫我看看什麼是錯,請
嗟我一直在嘗試怎麼回事解決這一問題進行過小時,我不知道。我得到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代碼。這裏是堆棧跟蹤:
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)
提供堆棧跟蹤爲好。 – Ambrish 2014-10-10 18:23:30
Iam對不起Iam新到這,什麼是堆棧跟蹤?爲什麼不能發送XML代碼.. – jojo 2014-10-10 18:24:52
我們需要堆棧跟蹤(LogCat中顯示的紅色錯誤日誌),但是我猜測R.id.testphone的類型不是'EditText'。無論是那個還是'ph0ne'都有錯誤的類型。你能發佈更多的代碼嗎? – aProperFox 2014-10-10 18:25:00