伙计们,我正在尝试实施新版本的谷歌地图,并且我已经完成了用谷歌编写的步骤,但是在尝试从手机运行地图时仍然出现错误。
这是我的java代码:
package com.example.e_order;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class Order_map extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_map);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_order_map, menu);
return true;
}
}
这是我的 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
和我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.e_order"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.e_order.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.e_order.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="mykey" />
这就是在我看来的logcat:
04-08 21:08:40.355: E/AndroidRuntime(14147): FATAL EXCEPTION: main
04-08 21:08:40.355: E/AndroidRuntime(14147): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.e_order/com.example.e_order.Order_map}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.os.Looper.loop(Looper.java:137)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.ActivityThread.main(ActivityThread.java:4507)
04-08 21:08:40.355: E/AndroidRuntime(14147): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 21:08:40.355: E/AndroidRuntime(14147): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 21:08:40.355: E/AndroidRuntime(14147): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-08 21:08:40.355: E/AndroidRuntime(14147): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-08 21:08:40.355: E/AndroidRuntime(14147): at dalvik.system.NativeStart.main(Native Method)
04-08 21:08:40.355: E/AndroidRuntime(14147): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-08 21:08:40.355: E/AndroidRuntime(14147): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.Activity.setContentView(Activity.java:1835)
04-08 21:08:40.355: E/AndroidRuntime(14147): at com.example.e_order.Order_map.onCreate(Order_map.java:12)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.Activity.performCreate(Activity.java:4465)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
04-08 21:08:40.355: E/AndroidRuntime(14147): ... 11 more
04-08 21:08:40.355: E/AndroidRuntime(14147): Caused by: java.lang.NullPointerException: name == null
04-08 21:08:40.355: E/AndroidRuntime(14147): at java.lang.VMClassLoader.findLoadedClass(Native Method)
04-08 21:08:40.355: E/AndroidRuntime(14147): at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:354)
04-08 21:08:40.355: E/AndroidRuntime(14147): at java.lang.ClassLoader.loadClass(ClassLoader.java:491)
04-08 21:08:40.355: E/AndroidRuntime(14147): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
04-08 21:08:40.355: E/AndroidRuntime(14147): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
04-08 21:08:40.355: E/AndroidRuntime(14147): ... 21 more
sry 4 漫长的任务。:)
新错误:
04-08 22:25:47.108: E/AndroidRuntime(19754): FATAL EXCEPTION: main 04-08 22:25:47.108: E/AndroidRuntime(19754): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable 04-08 22:25:47.108: E/AndroidRuntime(19754): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source) 04-08 22:25:47.108: E/AndroidRuntime(19754): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)