Android应用程序崩溃开始

时间:2015-03-26 11:12:05

标签: android crash

您好我已经开发了一个天气Android应用程序来读取xml文件并在屏幕上显示它们,但是当我运行应用程序时它崩溃的是logcat:

03-26 11:07:27.454    2300-2300/synctc.me.stormy D/AndroidRuntime﹕ Shutting down VM
03-26 11:07:27.455    2300-2300/synctc.me.stormy E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: synctc.me.stormy, PID: 2300
    java.lang.RuntimeException: Unable to start activity ComponentInfo{synctc.me.stormy/synctc.me.stormy.MainActivity}: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
            at synctc.me.stormy.MainActivity$$ViewInjector.inject(MainActivity$$ViewInjector.java:20)
            at synctc.me.stormy.MainActivity$$ViewInjector.inject(MainActivity$$ViewInjector.java:8)
            at butterknife.ButterKnife.inject(ButterKnife.java:317)
            at butterknife.ButterKnife.inject(ButterKnife.java:232)
            at synctc.me.stormy.MainActivity.onCreate(MainActivity.java:54)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

3 个答案:

答案 0 :(得分:0)

  1. 转到主要活动。
  2. 检查onCreateView()方法。
  3. 您正在通过文本视图解析相对布局,意味着您将相对布局ID转换为textview。

答案 1 :(得分:0)

找一条像(TextView)findViewById(R.id.something);要么你传递的是错误的id,要么你的演员是错的!

答案 2 :(得分:0)

在Logcat中双击此行,您将被引导至MainActivity,您可能已将RelativeLayout转换为Textview。

在synctc.me.stormy.MainActivity.onCreate(MainActivity.java:54)