Androidでフラグメントを使い始めたばかりで、フラグメントアクティビティ内で(全画面で)マップフラグメントを開始しようとして本当に時間がかかりました-すべてを試しました-1.マイプロジェクト> Androidツール>サポートライブラリの追加2.サポートの追加jar \ libsとしてのGoogle Playサービス
09-27 20:49:09.421: E/AndroidRuntime(11714): FATAL EXCEPTION: main
09-27 20:49:09.421: E/AndroidRuntime(11714): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.telofun/com.telofun.FragmentMap}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.os.Looper.loop(Looper.java:150)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.main(ActivityThread.java:4385)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.reflect.Method.invoke(Method.java:507)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
09-27 20:49:09.421: E/AndroidRuntime(11714): at dalvik.system.NativeStart.main(Native Method)
09-27 20:49:09.421: E/AndroidRuntime(11714): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.Activity.setContentView(Activity.java:1742)
09-27 20:49:09.421: E/AndroidRuntime(11714): at com.telofun.FragmentMap.onCreate(FragmentMap.java:23)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
09-27 20:49:09.421: E/AndroidRuntime(11714): ... 11 more
09-27 20:49:09.421: E/AndroidRuntime(11714): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
09-27 20:49:09.421: E/AndroidRuntime(11714): ... 20 more
09-27 20:49:09.421: E/AndroidRuntime(11714): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in loader dalvik.system.PathClassLoader[/data/app/com.telofun-1.apk]
09-27 20:49:09.421: E/AndroidRuntime(11714): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-27 20:49:09.421: E/AndroidRuntime(11714): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-27 20:49:09.421: E/AndroidRuntime(11714): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
それがレイアウトです -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
そしてコード -
package com.telofun;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Marker;
public class FragmentMap extends FragmentActivity {
GoogleMap googleMap;
Marker marker = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_map);
// Getting Google Play availability status
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if (status != ConnectionResult.SUCCESS) { // Google Play Services are
// not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
requestCode);
dialog.show();
} else { // Google Play Services are available
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
}
}
}