我尝试在我的Android应用中使用谷歌地图。两个星期我无法解决我的问题:当我添加时
private GoogleMap map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main); it doesn't work and app stopped, what to change?
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</fragment>
</LinearLayout>
我的日志,我有这个错误:
04-22 03:28:33.858 318-433/? E/libEGL﹕ eglMakeCurrent:671 error 3009 (EGL_BAD_MATCH)
04-22 03:28:34.038 29219-29219/com.example.messmap E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4745)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
at android.app.Activity.setContentView(Activity.java:1895)
at com.example.messmap.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
04-22 03:28:34.048 318-433/? E/libEGL﹕ eglMakeCurrent:671 error 3009 (EGL_BAD_MATCH)
04-22 03:28:35.269 853-1397/? E/Process﹕ Error getting pid for '0'
04-22 03:28:35.610 29352-29352/? E/ru.ivi.framework.utils.L﹕ onCreate (logMemory:237 03:28:35.622)
04-22 03:28:35.690 25607-25607/? E/ActivityThread﹕ Failed to find provider info for com.example.messmap.MetricaContentProvider
04-22 03:28:35.710 25607-29406/? E/ActivityThread﹕ Failed to find provider info for com.example.messmap.YPLContentProvider
04-22 03:28:40.514 437-437/? E/Parcel﹕ Reading a NULL string not supported here.
04-22 03:28:40.514 437-437/? E/Parcel﹕ Reading a NULL string not supported here.
如果有人遇到这个问题,请帮忙。片段有什么问题?我试图使用MapFragment,但它也没有结果