我正在My Android应用程序中实现Google Map V2。我已经完成了这两个链接中的所有步骤: http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ http://developer.android.com/google/play-services/setup.html 所以请不要将它们作为答案发送。我已下载Maps API,将其复制到Eclipse Workspace中,将其标记为库,在我的项目中引用它。但没有成功。我仍然得到错误:,有人可以帮助我。感谢apreciate。
以下是Log Cat信息:
01-13 11:41:09.106: I/dalvikvm(403): Could not find method info.androidhive.googlemapsv2.MainActivity.getFragmentManager, referenced from method info.androidhive.googlemapsv2.MainActivity.initilizeMap
01-13 11:41:09.106: W/dalvikvm(403): VFY: unable to resolve virtual method 27599: Linfo/androidhive/googlemapsv2/MainActivity;.getFragmentManager ()Landroid/app/FragmentManager;
01-13 11:41:09.106: D/dalvikvm(403): VFY: replacing opcode 0x6e at 0x0004
01-13 11:41:09.106: D/dalvikvm(403): VFY: dead code 0x0007-0028 in Linfo/androidhive/googlemapsv2/MainActivity;.initilizeMap ()V
01-13 11:41:09.772: W/dalvikvm(403): Unable to resolve superclass of Lcom/google/android/gms/maps/MapFragment; (26)
01-13 11:41:09.772: W/dalvikvm(403): Link of class 'Lcom/google/android/gms/maps/MapFragment;' failed
01-13 11:41:09.796: D/AndroidRuntime(403): Shutting down VM
01-13 11:41:09.796: W/dalvikvm(403): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-13 11:41:10.191: E/AndroidRuntime(403): FATAL EXCEPTION: main
01-13 11:41:10.191: E/AndroidRuntime(403): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-13 11:41:10.191: E/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 11:41:10.191: E/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:507)
01-13 11:41:10.191: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-13 11:41:10.191: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-13 11:41:10.191: E/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method)
01-13 11:41:10.191: E/AndroidRuntime(403): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-13 11:41:10.191: E/AndroidRuntime(403): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-13 11:41:10.191: E/AndroidRuntime(403): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.Activity.setContentView(Activity.java:1657)
01-13 11:41:10.191: E/AndroidRuntime(403): at info.androidhive.googlemapsv2.MainActivity.onCreate(MainActivity.java:27)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-13 11:41:10.191: E/AndroidRuntime(403): ... 11 more
01-13 11:41:10.191: E/AndroidRuntime(403): 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
01-13 11:41:10.191: E/AndroidRuntime(403): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-13 11:41:10.191: E/AndroidRuntime(403): ... 20 more
01-13 11:41:10.191: E/AndroidRuntime(403): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in loader dalvik.system.PathClassLoader[/data/app/info.androidhive.googlemapsv2-1.apk]
01-13 11:41:10.191: E/AndroidRuntime(403): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-13 11:41:10.191: E/AndroidRuntime(403): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-13 11:41:10.191: E/AndroidRuntime(403): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-13 11:41:10.191: E/AndroidRuntime(403): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
01-13 11:41:10.191: E/AndroidRuntime(403): ... 23 more
01-13 11:46:10.624: I/Process(403): Sending signal. PID: 403 SIG: 9
这是活动代码。
@SuppressLint("NewApi")
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
/*Could not find method info.androidhive.googlemapsv2.MainActivity.getFragmentManager,
referenced from method info.androidhive.googlemapsv2.MainActivity.initilizeMap*/
// Changing map type
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
// googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
// googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);
// Showing / hiding your current location
googleMap.setMyLocationEnabled(true);
// Enable / Disable zooming controls
googleMap.getUiSettings().setZoomControlsEnabled(false);
// Enable / Disable my location button
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
// Enable / Disable Compass icon
googleMap.getUiSettings().setCompassEnabled(true);
// Enable / Disable Rotate gesture
googleMap.getUiSettings().setRotateGesturesEnabled(true);
// Enable / Disable zooming functionality
googleMap.getUiSettings().setZoomGesturesEnabled(true);
double latitude = 17.385044;
double longitude = 78.486671;
// lets place some 10 random markers
for (int i = 0; i < 10; i++) {
// random latitude and logitude
double[] randomLocation = createRandLocation(latitude,
longitude);
// Adding a marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(randomLocation[0], randomLocation[1]))
.title("Hello Maps " + i);
Log.e("Random", "> " + randomLocation[0] + ", "
+ randomLocation[1]);
// changing marker color
if (i == 0)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
if (i == 1)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
if (i == 2)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
if (i == 3)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
if (i == 4)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
if (i == 5)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
if (i == 6)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED));
if (i == 7)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
if (i == 8)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
if (i == 9)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
googleMap.addMarker(marker);
// Move the camera to last position with a zoom level
if (i == 9) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(randomLocation[0],
randomLocation[1])).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
/**
* function to load map If map is not created it will create it for you
* */
@SuppressLint("NewApi") private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
}
}
}
/*
* creating random postion around a location for testing purpose only
*/
private double[] createRandLocation(double latitude, double longitude) {
return new double[] { latitude + ((Math.random() - 0.5) / 500),
longitude + ((Math.random() - 0.5) / 500),
150 + ((Math.random() - 0.5) * 10) };
}
}
答案 0 :(得分:0)
似乎你在片段中出错了。在您的错误消息中说明: 引起:android.view.InflateException:二进制XML文件行#6:错误膨胀类片段。