私のアプリケーションに問題があります。コンパイルの直後に、アプリケーションはランダムに閉じます。 LogCatをチェックすると、それがjava.lang.RuntimeExceptionであることが示されます。私はこれに関するすべてのフォーラムの記事を読んできたので、それに応じてコードを変更しましたが、問題は引き続きあります。助けて?アンドロイドアプリケーションのjava.lang.RuntimeException
コード:
public class DroidzActivity extends Activity implements OnGesturePerformedListener {
/** Called when the activity is first created. */
private GestureLibrary mLibrary;
private static final String TAG = MainThread.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MainGamePanel(this));
//requesting to turn the title OFF
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//make it full screen
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// set the MainGamePanel as the View
Log.d(TAG, "View added");
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
}
@Override
protected void onDestroy() {
Log.d(TAG, "Destroying...");
super.onDestroy();
}
@Override
protected void onStop() {
Log.d(TAG, "Stopping...");
super.onStop();
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
if (predictions.size() > 0) {
if (predictions.get(0).score > 1.0) {
String action = predictions.get(0).name;
if ("action_add".equals(action)) {
Toast.makeText(this, "Adding a contact", Toast.LENGTH_SHORT).show();
} else if ("action_delete".equals(action)) {
Toast.makeText(this, "Removing a contact", Toast.LENGTH_SHORT).show();
} else if ("action_refresh".equals(action)) {
Toast.makeText(this, "Reloading contacts", Toast.LENGTH_SHORT).show();
}
}
}
}
LogCat:
02-08 23:16:54.898: D/MainThread(3027): View added
02-08 23:16:54.937: D/AndroidRuntime(3027): Shutting down VM
02-08 23:16:54.937: W/dalvikvm(3027): threadid=1: thread exiting with uncaught exception (group=0x40015578)
02-08 23:16:54.949: E/AndroidRuntime(3027): FATAL EXCEPTION: main
02-08 23:16:54.949: E/AndroidRuntime(3027): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.obviam.droidz/net.obviam.droidz.DroidzActivity}: java.lang.NullPointerException
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.os.Looper.loop(Looper.java:130)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-08 23:16:54.949: E/AndroidRuntime(3027): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 23:16:54.949: E/AndroidRuntime(3027): at java.lang.reflect.Method.invoke(Method.java:507)
02-08 23:16:54.949: E/AndroidRuntime(3027): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
02-08 23:16:54.949: E/AndroidRuntime(3027): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
02-08 23:16:54.949: E/AndroidRuntime(3027): at dalvik.system.NativeStart.main(Native Method)
02-08 23:16:54.949: E/AndroidRuntime(3027): Caused by: java.lang.NullPointerException
02-08 23:16:54.949: E/AndroidRuntime(3027): at net.obviam.droidz.DroidzActivity.onCreate(DroidzActivity.java:42)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-08 23:16:54.949: E/AndroidRuntime(3027): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-08 23:16:54.949: E/AndroidRuntime(3027): ... 11 more
マニフェスト:setContentView()
オン
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.obviam.droidz"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:debuggable="true">
<activity
android:name=".DroidzActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
コードとマニフェストファイルをアップロードしてください。 –
ログカットとコード全体を投稿してください。 – Ghost
LogCatで例外を読んだ場合、おそらく1つ以上の「原因」行が別の例外に続いていることがわかります。最後の「原因」を見つけ、それに続く例外を投稿します。それが元の問題です。ここに投稿してください。私たちはあなたを助けることができます。 –