こんにちは私はこのコード行でNullPointerExceptionを取得しています:
findViewById(R.id.mapScreen).setDrawingCacheEnabled(true);
エミュレータでこのアクティビティを実行しようとすると。
私はそれが私のxmlの問題かもしれないと思ったが、すべてが私には正しいように見える。Javaコードは次のとおりです。
@Override
protected void onCreate(Bundle load)
{
super.onCreate(load);
//CODE FROM RIDETRACKING.JAVA
FrameLayout frame = new FrameLayout(this);
frame.setId(CONTENT_VIEW_ID);
setContentView(frame, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//END OF CODE FROM RIDETRACKING.JAVA
//setContentView(R.layout.map);
findViewById(R.id.mapScreen).setDrawingCacheEnabled(true);
mUnits = new UnitsI18n(this);
mLoggerServiceManager = new GPSLoggerServiceManager(this);
}
これが私のXMLコードです:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/mapScreen">
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0S37nJcRwodWjzWn7yJwFRc9qr5gvaD2bdvOpEQ"
android:visibility="visible" />
</RelativeLayout>
これが私のlogcat出力です:
03-20 16:14:05.294: E/AndroidRuntime(2424): FATAL EXCEPTION: main
03-20 16:14:05.294: E/AndroidRuntime(2424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gpstracker/com.polaris.epicriders.Rides.RideTracking}: java.lang.NullPointerException
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.os.Looper.loop(Looper.java:137)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-20 16:14:05.294: E/AndroidRuntime(2424): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 16:14:05.294: E/AndroidRuntime(2424): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 16:14:05.294: E/AndroidRuntime(2424): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-20 16:14:05.294: E/AndroidRuntime(2424): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-20 16:14:05.294: E/AndroidRuntime(2424): at dalvik.system.NativeStart.main(Native Method)
03-20 16:14:05.294: E/AndroidRuntime(2424): Caused by: java.lang.NullPointerException
03-20 16:14:05.294: E/AndroidRuntime(2424): at com.android.riders.Rides.RideTracking.onCreate(RideTracking.java:181)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.Activity.performCreate(Activity.java:5104)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-20 16:14:05.294: E/AndroidRuntime(2424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-20 16:14:05.294: E/AndroidRuntime(2424): ... 11 more