2014-10-10 9 views
0

가 여기 확인 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) 
+0

뿐만 아니라 스택 추적을 제공에서의 ID를 당신의 EditText을 확인합니다. – Ambrish

+0

이게 미안해, 스택 트레이스 란 무엇입니까? 그리고 왜 XML 코드를 보낼 수 없는지 .. – jojo

+1

스택 추적 (LogCat에 나타나는 빨간색 오류 로그)이 필요합니다. 그러나 R.id.testphone의 유형이 'EditText'가 아님을 추측합니다. 그것 또는 'ph0ne'이 잘못된 유형입니다. 더 많은 코드를 게시 할 수 있습니까? – aProperFox

답변

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

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

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

을 변경해야한다는 것을 의미;

나보기가 EditText을해야합니다, 당신은 당신이 당신의 디자인 ID에 다스 려에 실수를 생각 EditText

+0

글쎄 그건 작동하지 않습니다. 만약 내가 그것을 변경하고 EditText가 필요하지만 LinearLayout을 찾았다 고 밝히지 빨간색 밑줄 라인을 얻을 – jojo

+0

그럼 문제는 'ph0ne'LinearLayout 유형이 있습니다. 'TextView ph0ne;'으로 변경하십시오. 초기화에서. – aProperFox

+0

닫는 태그가이므로 @jojo가 적합합니다. 닫기 태그를 넣는 경우이어야합니다. 또는 닫기 태그를 제거하고 마지막 꺽쇠 괄호 앞에 슬래시를 추가하는 첫 번째 태그 만 사용할 수 있습니다. – GVillani82

0

에서 아이디 testphone와보기를 (즉, LinearLayout입니다) 변경해야 할, 제발 '당신이 당신의 오류 로그에서 보는 바와 같이,이 ID R.id.testphoneLinearLayout 참조하기 때문에 당신의 edit-text 확인,의 ID를'당신의 XML

+0

아니요 :(.<글고 로이드 : layout_width = "match_parent" 로이드 : layout_height = "wrap_content" 로이드 : inputType = "전화" 로이드 : EMS = "10" 로이드 = "@ + ID/testphone"ID /> – jojo