Googleマップビューに表示するデフォルトのズームコントロールを取得しようとしています。 私はthisコードを見ていました。しかし、getZoomControls()は推奨されていません。mapView非推奨のメソッドgetZoomControls?
代わりにsetBuiltInZoomControlsを使用しようとしていますが、エラーが発生しています。
私がデバッグするときは例外です。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.maptab2/com.test.maptab2.MapTabView}: java.lang.NullPointerException
02-05 09:49:21.239: W/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-05 09:49:22.616: E/AndroidRuntime(357): FATAL EXCEPTION: main
02-05 09:49:22.616: E/AndroidRuntime(357): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
02-05 09:49:22.616: E/AndroidRuntime(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-05 09:49:22.616: E/AndroidRuntime(357): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-05 09:49:22.616: E/AndroidRuntime(357): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-05 09:49:22.616: E/AndroidRuntime(357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-05 09:49:22.616: E/AndroidRuntime(357): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 09:49:22.616: E/AndroidRuntime(357): at android.os.Looper.loop(Looper.java:123)
02-05 09:49:22.616: E/AndroidRuntime(357): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-05 09:49:22.616: E/AndroidRuntime(357): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 09:49:22.616: E/AndroidRuntime(357): at java.lang.reflect.Method.invoke(Method.java:521)
02-05 09:49:22.616: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-05 09:49:22.616: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-05 09:49:22.616: E/AndroidRuntime(357): at dalvik.system.NativeStart.main(Native Method)
02-05 09:49:22.616: E/AndroidRuntime(357): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivit
18行目はmapView.setBuiltInZoomControls(true)です。
私のマップはタブ内に表示されています。これはメインクラス(タブを扱う - それぞれのクラスが独自のクラスです)でこれが好きです。
Intent i = new Intent(this,MapTabView.class);
TabHost.TabSpec spec;
spec = getTabHost().newTabSpec("tab1");
spec.setContent(i);
spec.setIndicator("Map");
getTabHost().addTab(spec);
ここに私のコードです:
MapTabView.java
package com.test.maptab2;
import android.os.Bundle;
import android.view.View;
import android.widget.ZoomControls;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapTabView extends MapActivity {
MapView mapView;
@Override
public void onCreate (Bundle icicle){
super.onCreate(icicle);
setContentView(R.layout.maptabview);
mapView = (MapView) findViewById(R.layout.maptabview);
mapView.setBuiltInZoomControls(true);
}
@Override
public boolean isRouteDisplayed(){
return false;
}
}
maptabview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/maptablayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Actual map -->
<com.google.android.maps.MapView android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0HRMcD5o6WrBVhmwbWpeyeavZ67PXWOvJeeCx2g"/>
</RelativeLayout>
私は、これは私は1と同じエラーで実現してきましたここに来る:Android unable to start activity, error inflating class?。
でそれを参照するために; 詳細を含む質問を編集します – Ephemeros
findViewById(R.layout.maptabview);あなたのXMLでfindViewById(R.layout.mapview); (あなたのXMLに設定された実際のID) – znat
'は解決できないか、フィールドではありません。私はR.layoutがその中の要素ではなく、レイアウトファイル参照(メインと任意の追加)を保存していると思ったのですか? – Ephemeros