:私はアンドロイドグーグルマップ:私はGoogleのチュートリアルでまったく同じ手順に続いていたnullポインタ例外
を "強制終了" しまっながら... http://developer.android.com/guide/tutorials/views/hello-mapview.html
はここに私のコードです:
public class TrainstationActivity extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
mapview.setBuiltInZoomControls(true);
}
private MapView mapview;
LinearLayout linearLayout;
}
private void findViews() {
mapview=(MapView)findViewById(R.id.map);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
logcatの "nullポインタ例外"の結果
ここにログcat:
01-10 20:09:31.564: D/dalvikvm(789): GC_CONCURRENT freed 1161K, 54% free 3151K/6727K, external 1625K/2137K, paused 4ms+4ms
01-10 20:09:31.824: D/dalvikvm(789): GC_CONCURRENT freed 531K, 51% free 3311K/6727K, external 1625K/2137K, paused 4ms+7ms
01-10 20:09:32.034: D/AndroidRuntime(789): Shutting down VM
01-10 20:09:32.034: W/dalvikvm(789): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-10 20:09:32.044: E/AndroidRuntime(789): FATAL EXCEPTION: main
01-10 20:09:32.044: E/AndroidRuntime(789): java.lang.RuntimeException: Unable to start activity ComponentInfo{trian.station/trian.station.TrainstationActivity}: java.lang.NullPointerException
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.os.Looper.loop(Looper.java:130)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-10 20:09:32.044: E/AndroidRuntime(789): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 20:09:32.044: E/AndroidRuntime(789): at java.lang.reflect.Method.invoke(Method.java:507)
01-10 20:09:32.044: E/AndroidRuntime(789): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-10 20:09:32.044: E/AndroidRuntime(789): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-10 20:09:32.044: E/AndroidRuntime(789): at dalvik.system.NativeStart.main(Native Method)
01-10 20:09:32.044: E/AndroidRuntime(789): Caused by: java.lang.NullPointerException
01-10 20:09:32.044: E/AndroidRuntime(789): at trian.station.TrainstationActivity.onCreate(TrainstationActivity.java:18)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-10 20:09:32.044: E/AndroidRuntime(789): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-10 20:09:32.044: E/AndroidRuntime(789): ... 11 more
01-10 20:09:33.934: D/dalvikvm(789): GC_CONCURRENT freed 830K, 54% free 3098K/6727K, external 1641K/2137K, paused 3ms+5ms
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="********"
android:clickable="true"
/>
<!--<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
-->
マニフェスト
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo.android.trainstation"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".TrainStation"
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>
<uses-sdk android:minSdkVersion="5" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
はSB私が間違っていたものを私に教えることができますか?
P.S. なしmapview.setBuiltInZoomControls(true); この行は、マップを正しく実行できる
まだ動作していない、私は質問を投稿する前にこれを試してみた とにかく:) –