尝试启动新活动时,Android 应用程序崩溃

Posted

技术标签:

【中文标题】尝试启动新活动时,Android 应用程序崩溃【英文标题】:Android Application crashes when trying to start new activity 【发布时间】:2013-06-24 23:17:40 【问题描述】:

我正在尝试启动一个新的 Activity,android。这是创建以下错误。 注意:我已经更新了清单中的新活动

Logcat

06-27 18:00:39.543: D/AndroidRuntime(908): Shutting down VM
06-27 18:00:39.543: W/dalvikvm(908): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-27 18:00:39.563: E/AndroidRuntime(908): FATAL EXCEPTION: main
06-27 18:00:39.563: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfocom.dipl.smpm.smpm/com.dipl.smpm.smpm.UpdateTask: android.view.InflateException: Binary XML file line #15: Error inflating class button
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.os.Looper.loop(Looper.java:123)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-27 18:00:39.563: E/AndroidRuntime(908):  at java.lang.reflect.Method.invokeNative(Native Method)
06-27 18:00:39.563: E/AndroidRuntime(908):  at java.lang.reflect.Method.invoke(Method.java:521)
06-27 18:00:39.563: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-27 18:00:39.563: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-27 18:00:39.563: E/AndroidRuntime(908):  at dalvik.system.NativeStart.main(Native Method)
06-27 18:00:39.563: E/AndroidRuntime(908): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class button
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-27 18:00:39.563: E/AndroidRuntime(908):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.Activity.setContentView(Activity.java:1647)
06-27 18:00:39.563: E/AndroidRuntime(908):  at com.dipl.smpm.smpm.UpdateTask.onCreate(UpdateTask.java:11)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-27 18:00:39.563: E/AndroidRuntime(908):  ... 11 more
06-27 18:00:39.563: E/AndroidRuntime(908): Caused by: java.lang.ClassNotFoundException: android.view.button in loader dalvik.system.PathClassLoader[/data/app/com.dipl.smpm.smpm-2.apk]
06-27 18:00:39.563: E/AndroidRuntime(908):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-27 18:00:39.563: E/AndroidRuntime(908):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-27 18:00:39.563: E/AndroidRuntime(908):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.createView(LayoutInflater.java:466)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
06-27 18:00:39.563: E/AndroidRuntime(908):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-27 18:00:39.563: E/AndroidRuntime(908):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)

【问题讨论】:

发布您的 xml,也许是 ActivityonCreate()。我也会尝试清理你的项目 膨胀 XML 时出错。在此处发布 XML。 【参考方案1】:

您似乎已在 xml 布局中将您的按钮定义为

     <button
       android:layout_
       ..........

                  />

但是你必须写一个大写的b

     <Button
        android:layout_
         ............

                   />

这就是错误消息中的行所说的

    Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class button  <--- You wrote button, but it has to be Button

【讨论】:

太棒了.......老兄!!!我很着急,我挣扎了大约 3 天 :) 谢谢...@Opiatefuchs 没问题,即使你是高级开发人员也会发生这种情况:)

以上是关于尝试启动新活动时,Android 应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章

重新启动活动时,Android Wear 上的融合位置提供程序会导致崩溃

启动新活动 Android 时出错

崩溃新的android进程停止整个应用程序

Android 9 (API 28) 活动在启动时崩溃 (setContentView)

关闭并重新打开应用程序时Android崩溃

在Firebase身份验证后启动MainActivity