我是 Android 的新编程人员,我正在阅读“Hello,Android”一书,第 3 版。第二章是制作数独的教程。即使使用书中的代码,当我运行程序时,它也会安装在 AVD 中,但突然,它说“不幸的是,数独已停止”。我在互联网上搜索了没有解决方案。
代码如下:
主文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/main_title" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/new_game_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/about_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/exit_label" />
</LinearLayout>
数独.java
package org.example.sudoku;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Sudoku extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
AndroidManifest.xlm
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.sudoku"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/main_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
日志猫是:
08-22 22:28:38.333: I/Process(610): Sending signal. PID: 610 SIG: 9
08-22 22:28:58.142: E/Trace(653): error opening trace file: No such file or directory (2)
08-22 22:28:58.492: D/AndroidRuntime(653): Shutting down VM
08-22 22:28:58.492: W/dalvikvm(653): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-22 22:28:58.503: E/AndroidRuntime(653): FATAL EXCEPTION: main
08-22 22:28:58.503: E/AndroidRuntime(653): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.example.sudoku/org.example.sudoku.Main}: java.lang.ClassNotFoundException: org.example.sudoku.Main
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.os.Looper.loop(Looper.java:137)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-22 22:28:58.503: E/AndroidRuntime(653): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 22:28:58.503: E/AndroidRuntime(653): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 22:28:58.503: E/AndroidRuntime(653): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-22 22:28:58.503: E/AndroidRuntime(653): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-22 22:28:58.503: E/AndroidRuntime(653): at dalvik.system.NativeStart.main(Native Method)
08-22 22:28:58.503: E/AndroidRuntime(653): Caused by: java.lang.ClassNotFoundException: org.example.sudoku.Main
08-22 22:28:58.503: E/AndroidRuntime(653): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-22 22:28:58.503: E/AndroidRuntime(653): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-22 22:28:58.503: E/AndroidRuntime(653): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-22 22:28:58.503: E/AndroidRuntime(653): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-22 22:28:58.503: E/AndroidRuntime(653): ... 11 more