扩展类片段时出错,试图显示地图

时间:2013-04-29 15:58:21

标签: android class fragment

我是Android开发人员的新手,我试图在我的应用程序中包含一些地图,我从一些简单的东西开始,只显示一个以我住的地方为中心的地图。我一直在尝试很多东西来解决我的问题,没有任何成功,我会留下我的代码和错误日志。如果你能帮助我,我将非常感激:D

这是java:

    package com.example.proyect2;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.MapFragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

public class AddPlace extends Activity {

    static final LatLng PAMPLONA = new LatLng(42.811, -1.648);
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_place);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.amap)).getMap();
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(PAMPLONA, 15));

            if (map!=null){
              Marker pamplona = map.addMarker(new MarkerOptions()
                  .position(PAMPLONA)
                  .title("Pamplona")
                  .snippet("Nota")
                  .icon(BitmapDescriptorFactory
                      .fromResource(R.drawable.ic_launcher)));
            }

    }

    @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_add_place, 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=".AddPlace"
    android:background="#333333" >

    <fragment
     android:id="@+id/amap"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     class="com.google.android.gms.maps.MapFragment"/>

</RelativeLayout>

最后是错误日志:

04-29 17:44:32.320: D/libEGL(19416): loaded /system/lib/egl/libEGL_mali.so
04-29 17:44:32.330: D/libEGL(19416): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-29 17:44:32.330: D/libEGL(19416): loaded /system/lib/egl/libGLESv2_mali.so
04-29 17:44:32.335: D/(19416): Device driver API match
04-29 17:44:32.335: D/(19416): Device driver API version: 10
04-29 17:44:32.335: D/(19416): User space API version: 10 
04-29 17:44:32.335: D/(19416): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 
04-29 17:44:32.380: D/OpenGLRenderer(19416): Enabling debug mode 0
04-29 17:44:33.955: E/SpannableStringBuilder(19416): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-29 17:44:33.955: E/SpannableStringBuilder(19416): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-29 17:44:34.555: D/dalvikvm(19416): GC_CONCURRENT freed 105K, 8% free 12515K/13511K, paused 15ms+2ms, total 33ms
04-29 17:44:34.555: D/dalvikvm(19416): WAIT_FOR_CONCURRENT_GC blocked 9ms
04-29 17:44:34.975: D/dalvikvm(19416): GC_CONCURRENT freed 234K, 9% free 12755K/13895K, paused 5ms+4ms, total 52ms
04-29 17:44:35.060: D/AndroidRuntime(19416): Shutting down VM
04-29 17:44:35.060: W/dalvikvm(19416): threadid=1: thread exiting with uncaught exception (group=0x40fe72a0)
04-29 17:44:35.080: E/AndroidRuntime(19416): FATAL EXCEPTION: main
04-29 17:44:35.080: E/AndroidRuntime(19416): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.proyect2/com.example.proyect2.AddPlace}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.os.Looper.loop(Looper.java:137)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.ActivityThread.main(ActivityThread.java:4898)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at java.lang.reflect.Method.invokeNative(Native Method)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at java.lang.reflect.Method.invoke(Method.java:511)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at dalvik.system.NativeStart.main(Native Method)
04-29 17:44:35.080: E/AndroidRuntime(19416): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.Activity.setContentView(Activity.java:1924)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.example.proyect2.AddPlace.onCreate(AddPlace.java:24)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.Activity.performCreate(Activity.java:5206)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
04-29 17:44:35.080: E/AndroidRuntime(19416):    ... 11 more
04-29 17:44:35.080: E/AndroidRuntime(19416): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.ab.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.ab.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.ab.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.ag.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.ag.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.bw.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at maps.z.r.onCreateView(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.os.Binder.transact(Binder.java:326)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.maps.MapFragment$b.onCreateView(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.internal.e$4.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.internal.e.a(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.internal.e.onCreateView(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.app.Activity.onCreateView(Activity.java:4857)
04-29 17:44:35.080: E/AndroidRuntime(19416):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-29 17:44:35.080: E/AndroidRuntime(19416):    ... 21 more
04-29 17:44:44.865: I/Process(19416): Sending signal. PID: 19416 SIG: 9

提前感谢您的帮助! :)

0 个答案:

没有答案