マップビューを備えたMapActivityがあります。正常に動作します。次に、MapViewにSeekBarを追加します。一番下にある必要がありますが、マップビューにあります。ユーザーはスクロールして距離を設定します。なんでもいい。私の問題は、findViewById()で到達したときに、そこに配置しようとしているビューがnullになることです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="mykey"/>
<SeekBar
android:id="@+id/DistanceBar"
android:max="2000"
android:progress="2000"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="14dip"></SeekBar>
</RelativeLayout>
私はこのようにそれに到達しようとしています:
public class MyActivity extends MapActivity implements LocationListener {
...
SeekBar DistanceBar;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
DistanceBar = (SeekBar) findViewById(R.id.DistanceBar); //This is afterwards null.
私は至る所で調査を行いましたが、同様の問題を見つけることができませんでした。誰かが非常によく似たものを使用しました。したがって、nullであることを無視し、onCreate()でSeekBarを呼び出しませんでした。しかし、SeekBarはまったく描画されていません。マップアクティビティに他のビューを追加できませんか?
アイデアをありがとう!
重要な編集:グラフィックレイアウトビューアには、マップビューの下部にあるはずのSeekBarが表示されます。
まだNullPointerExceptionが発生します:エラー/ AndroidRuntime(12738):致命的な例外:メイン
エラー/AndroidRuntime(12738):java.lang.RuntimeException:アクティビティを開始できませんComponentInfo {com.MyApps.MapLocations / com.MyApps.MapLocations.MyActivity}:java.lang.NullPointerException
エラー/AndroidRuntime(12738):android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)で
エラー/AndroidRuntime(12738):android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)で
エラー/AndroidRuntime(12738):android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
エラー/AndroidRuntime(12738):android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
エラー/AndroidRuntime(12738):android.os.Handler.dispatchMessage(Handler.java:99)で
エラー/AndroidRuntime(12738):android.os.Looper.loop(Looper.java:123)で
エラー/AndroidRuntime(12738):android.app.ActivityThread.main(ActivityThread.java:4627)で
エラー/AndroidRuntime(12738):java.lang.reflect.Method.invokeNative(ネイティブメソッド)で
エラー/AndroidRuntime(12738):java.lang.reflect.Method.invoke(Method.java:521)で
エラー/AndroidRuntime(12738):com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:871)
エラー/AndroidRuntime(12738):com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
エラー/AndroidRuntime(12738):dalvik.system.NativeStart.main(ネイティブメソッド)
エラー/AndroidRuntime(12738):原因:java.lang.NullPointerException
エラー/AndroidRuntime(12738):com.MyApps.MapLocations.MyActivity.setupSeekbar(MyActivity.java:343)
エラー/AndroidRuntime(12738):com.MyApps.MapLocations.MyActivity.onCreate(MyActivity.java:89)で
エラー/AndroidRuntime(12738):android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
エラー/AndroidRuntime(12738):android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)で
エラー/AndroidRuntime(12738):...11詳細
HierarchyViewerの結果は次のとおりです。