我有一个旧应用程序,我正在尝试更新以添加地图。Google-services 在 Eclipse 中添加到我的工作区,并在我的项目中创建为库引用。清单中添加的 Mapkey 和权限。
我阅读了很多教程,但我无法解决以下问题:
08-12 21:40:28.275: E/cutils-trace(771): Error opening trace file: No such file or directory (2)
08-12 21:40:33.435: E/AndroidRuntime(771): FATAL EXCEPTION: main
08-12 21:40:33.435: E/AndroidRuntime(771): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.data/com.example.data.activity.MapsActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.os.Looper.loop(Looper.java:137)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-12 21:40:33.435: E/AndroidRuntime(771): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 21:40:33.435: E/AndroidRuntime(771): at java.lang.reflect.Method.invoke(Method.java:525)
08-12 21:40:33.435: E/AndroidRuntime(771): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-12 21:40:33.435: E/AndroidRuntime(771): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-12 21:40:33.435: E/AndroidRuntime(771): at dalvik.system.NativeStart.main(Native Method)
08-12 21:40:33.435: E/AndroidRuntime(771): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-12 21:40:33.435: E/AndroidRuntime(771): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-12 21:40:33.435: E/AndroidRuntime(771): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.Activity.setContentView(Activity.java:1895)
08-12 21:40:33.435: E/AndroidRuntime(771): at com.example.data.activity.MapsActivity.onCreate(MapsActivity.java:22)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.Activity.performCreate(Activity.java:5133)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-12 21:40:33.435: E/AndroidRuntime(771): ... 11 more
08-12 21:40:33.435: E/AndroidRuntime(771): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
08-12 21:40:33.435: E/AndroidRuntime(771): at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
08-12 21:40:33.435: E/AndroidRuntime(771): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-12 21:40:33.435: E/AndroidRuntime(771): ... 21 more
我的活动:
package com.example.data.activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.example.data.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
private LatLng frameworkSystemLocation = new LatLng(-19.92550, -43.64058);
private GoogleMap map;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
Marker frameworkSystem = map.addMarker(new MarkerOptions()
.position(frameworkSystemLocation)
.title("Framework System"));
// Move a câmera para Framework System com zoom 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(frameworkSystemLocation , 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
我的 xml 布局文件:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
有谁知道如何解决?