所以我在Mac OS上,下载Android工作室,下载了英特尔HAXM,开始编写脚本并完成本教程的结尾:
https://developer.android.com/training/basics/firstapp/building-ui.html
脚本实际运行,但是当我通过我的模拟器运行它时,模拟器会说“我的第一个应用程序已经停止工作”,我在调试菜单中得到了以下内容。
我仔细按照说明操作,对Java有基本的了解,但我对Android并不熟悉。谁能让我知道我哪里出错?
提前致谢!
Cab_Russell
02-24 22:41:24.798 2781-2781/com.example.dannyrussell.myfirstapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.dannyrussell.myfirstapp, PID: 2781
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dannyrussell.myfirstapp/com.example.dannyrussell.myfirstapp.MyActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class button
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: android.view.InflateException: Binary XML file line #15: Error inflating class button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.example.dannyrussell.myfirstapp.MyActivity.onCreate(MyActivity.java:14)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
答案 0 :(得分:1)
问题在堆栈跟踪中被识别出来(虽然可能很模糊)。
在创建视图时,Android会为布局XML中的对象创建Java对象。它说它无法为类“按钮”创建Java对象。由于您可能想要的类是“Button”,因此请确保您的布局XML正确(区分大小写)