1

リストからツアーが選択されたときに MapView を開始する必要がある Android アプリに取り組んでいます。ただし、インテントを介してこの MapView を開こうとするたびに、アプリがクラッシュするようです...

これが私のコードです:

MainActivity.java:

public class MainActivity extends Activity {
    public final static String SELECTED_TOUR = "com.me.tourapp.TOUR";
    public static TourListAdapter tourListAdapter;
    private static int selectedTour;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
    }

    public void startTour(View view) {
        Intent intent = new Intent(view.getContext(), TourMapActivity.class);
        intent.putExtra(SELECTED_TOUR, selectedTour);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        ...
    }

}

TourMapActivity.java:

public class TourMapActivity extends Activity {

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tour_map);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }

        //check if tour is passed via intent (test):
        Intent intent = getIntent();
        int tourIndex = Integer.parseInt(intent.getStringExtra(MainActivity.SELECTED_TOUR));
        Toast.makeText(getApplicationContext(), "the tour: "+ tourIndex, Toast.LENGTH_LONG).show();
    }
}

activity_tour_map.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

</LinearLayout>

マニフェストからのいくつかのスニペット:

<permission
    android:name="com.me.tourapp.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.me.tourapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-library android:name="com.google.android.maps" />

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBqs_*****"/>

また、android-support-v4.jar を Java ビルド パスに含め、Google Play サービスをインストールしてインポートしました...

どこでエラーを起こしているのか手がかりがありません...

編集: logcat を追加しました:

E/AndroidRuntime(28248): FATAL EXCEPTION: main
E/AndroidRuntime(28248): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hansvn.plaktour/com.hansvn.plaktour.TourMapActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(28248):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
E/AndroidRuntime(28248):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
E/AndroidRuntime(28248):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
E/AndroidRuntime(28248):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
E/AndroidRuntime(28248):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(28248):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(28248):    at android.app.ActivityThread.main(ActivityThread.java:4898)
E/AndroidRuntime(28248):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28248):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(28248):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
E/AndroidRuntime(28248):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
E/AndroidRuntime(28248):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(28248): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(28248):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
E/AndroidRuntime(28248):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime(28248):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime(28248):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(28248):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime(28248):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
E/AndroidRuntime(28248):    at android.app.Activity.setContentView(Activity.java:1924)
E/AndroidRuntime(28248):    at com.hansvn.plaktour.TourMapActivity.onCreate(TourMapActivity.java:16)
E/AndroidRuntime(28248):    at android.app.Activity.performCreate(Activity.java:5206)
E/AndroidRuntime(28248):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
E/AndroidRuntime(28248):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
E/AndroidRuntime(28248):    ... 11 more
E/AndroidRuntime(28248): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(28248):    at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
E/AndroidRuntime(28248):    at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime(28248):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime(28248):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
E/AndroidRuntime(28248):    ... 21 more
E/AndroidRuntime(28248): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
E/AndroidRuntime(28248):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime(28248):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(28248):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(28248):    at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
E/AndroidRuntime(28248):    ... 24 more
4

1 に答える 1