我正在从Ed褐发女郎的书“Hello,Android”中学习Android编程
在其中代码(以下)是给定的,我按原样输入,仍然是强制关闭错误。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/Background"
android:gravity="center"
android:padding="35dip"
>
<Textview
android:text="@string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp" />
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:id="@+id/continue_button"
android:text="@string/continue_label"/>
<Button
android:id="@+id/new_button"
android:text="@string/new_game_label"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/about_button"
android:text="@string/about_label" />
<Button
android:id="@+id/exit_button"
androidLtext="@string/exit_label" />
</TableRow>
</TableLayout>
</LinearLayout>
Log Cat:
04-01 15:12:08.370: D/AndroidRuntime(410): Shutting down VM
04-01 15:12:08.370: W/dalvikvm(410): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-01 15:12:08.420: E/AndroidRuntime(410): FATAL EXCEPTION: main
04-01 15:12:08.420: E/AndroidRuntime(410): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.sudoku/org.example.sudoku.Sudoku}: android.view.InflateException: Binary XML file line #10: Error inflating class Textview
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread.access$1600(ActivityThread.java:117)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.os.Looper.loop(Looper.java:123)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-01 15:12:08.420: E/AndroidRuntime(410): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 15:12:08.420: E/AndroidRuntime(410): at java.lang.reflect.Method.invoke(Method.java:507)
04-01 15:12:08.420: E/AndroidRuntime(410): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-01 15:12:08.420: E/AndroidRuntime(410): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-01 15:12:08.420: E/AndroidRuntime(410): at dalvik.system.NativeStart.main(Native Method)
04-01 15:12:08.420: E/AndroidRuntime(410): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class Textview
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-01 15:12:08.420: E/AndroidRuntime(410): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.Activity.setContentView(Activity.java:1657)
04-01 15:12:08.420: E/AndroidRuntime(410): at org.example.sudoku.Sudoku.onCreate(Sudoku.java:11)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-01 15:12:08.420: E/AndroidRuntime(410): ... 12 more
04-01 15:12:08.420: E/AndroidRuntime(410): Caused by: java.lang.ClassNotFoundException: android.view.Textview in loader dalvik.system.PathClassLoader[/data/app/org.example.sudoku-1.apk]
04-01 15:12:08.420: E/AndroidRuntime(410): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-01 15:12:08.420: E/AndroidRuntime(410): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-01 15:12:08.420: E/AndroidRuntime(410): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
04-01 15:12:08.420: E/AndroidRuntime(410): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-01 15:12:08.420: E/AndroidRuntime(410): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-01 15:12:08.420: E/AndroidRuntime(410): ... 21 more
04-01 15:12:12.681: I/Process(410): Sending signal. PID: 410 SIG: 9
04-01 15:12:34.881: W/KeyCharacterMap(424): No keyboard for id 0
04-01 15:12:34.881: W/KeyCharacterMap(424): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-01 15:30:15.661: D/AndroidRuntime(495): Shutting down VM
04-01 15:30:15.661: W/dalvikvm(495): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-01 15:30:15.741: E/AndroidRuntime(495): FATAL EXCEPTION: main
04-01 15:30:15.741: E/AndroidRuntime(495): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.sudoku/org.example.sudoku.Sudoku}: android.view.InflateException: Binary XML file line #10: Error inflating class Textview
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread.access$1600(ActivityThread.java:117)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.os.Looper.loop(Looper.java:123)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-01 15:30:15.741: E/AndroidRuntime(495): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 15:30:15.741: E/AndroidRuntime(495): at java.lang.reflect.Method.invoke(Method.java:507)
04-01 15:30:15.741: E/AndroidRuntime(495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-01 15:30:15.741: E/AndroidRuntime(495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-01 15:30:15.741: E/AndroidRuntime(495): at dalvik.system.NativeStart.main(Native Method)
04-01 15:30:15.741: E/AndroidRuntime(495): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class Textview
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-01 15:30:15.741: E/AndroidRuntime(495): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.Activity.setContentView(Activity.java:1657)
04-01 15:30:15.741: E/AndroidRuntime(495): at org.example.sudoku.Sudoku.onCreate(Sudoku.java:11)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-01 15:30:15.741: E/AndroidRuntime(495): ... 12 more
04-01 15:30:15.741: E/AndroidRuntime(495): Caused by: java.lang.ClassNotFoundException: android.view.Textview in loader dalvik.system.PathClassLoader[/data/app/org.example.sudoku-2.apk]
04-01 15:30:15.741: E/AndroidRuntime(495): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-01 15:30:15.741: E/AndroidRuntime(495): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-01 15:30:15.741: E/AndroidRuntime(495): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
04-01 15:30:15.741: E/AndroidRuntime(495): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-01 15:30:15.741: E/AndroidRuntime(495): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-01 15:30:15.741: E/AndroidRuntime(495): ... 21 more
我还在学习,我搜索了其他可以帮助解决我的问题的问题,但它让我很困惑,因为我对android编程还不太了解。
谢谢:)
答案 0 :(得分:1)
布局文件中有一个简单的拼写错误,它应该是TextView
而不是Textview
。
答案 1 :(得分:1)
来自你的logcat:
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class Textview
E/AndroidRuntime(495): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
所以我们知道文本视图是个问题。
<Textview
android:text="@string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp" />
删除结束标记之前的空格,并将Textview更改为TextView。
<TextView
android:text="@string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp"/>