不幸的是myAndroidapp已经停止了。应用包括地图

时间:2013-05-09 06:14:30

标签: android google-maps mapactivity

我正在尝试在我的Android设备上构建一个谷歌地图应用程序。它工作正常,但最近它一直在给出错误。

应用程序提供错误致命:主要。我发布了代码和日志错误文件。请帮我解决这个问题。 我的Android设备有什么问题,因为相同的代码对我来说工作正常。 Android Manifest: -

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemaps"
    android:versionCode="1"
    android:versionName="1.0" >
       <uses-sdk android:minSdkVersion="8" 
    android:targetSdkVersion="17"/>
    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <!--  Add Google Map Library -->
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:label="@string/app_name"
        android:name=".MapsActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBX1XULUbZ8KEpvy60JsDKxmYWtVuIs2X0"/>
    </application>
    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
    <permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE"                   android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />



      </manifest>

MapActivity.java

 package com.example.googlemaps;
 import android.app.Dialog;
 import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
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.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;


public class MapsActivity extends FragmentActivity {
     //Intent in = getIntent();
     //String latitude = in.getStringExtra("latitude");
     //String longitude = in.getStringExtra("longitude");


    GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        // Showing status
        if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();

        }else { // Google Play Services are available


            // Double latitude1=Double.parseDouble(latitude);
            // Double longitude1=Double.parseDouble(longitude);

            // Getting reference to the SupportMapFragment of activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();

            // Enabling MyLocation Layer of Google Map
            googleMap.setMyLocationEnabled(true);

            googleMap.addMarker(new MarkerOptions().position(new LatLng(28.62293,77.36403)).title("SaveMe").snippet("Place of Interest").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));

                //System.out.println("Marker added");


            // Showing the current location in Google Map
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(28.62293, 77.36403)));

            // Zoom in the Google Map
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(14));

            // Setting latitude and longitude in the TextView tv_location
        }
    }




}

mail.xml: -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"

        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

错误: -

05-09 11:28:37.156: W/dalvikvm(27963): threadid=1: thread exiting with uncaught exception (group=0x40aa1210)
05-09 11:28:37.156: E/AndroidRuntime(27963): FATAL EXCEPTION: main
05-09 11:28:37.156: E/AndroidRuntime(27963): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.Activity.setContentView(Activity.java:1835)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.example.googlemaps.MapsActivity.onCreate(MapsActivity.java:28)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.Activity.performCreate(Activity.java:4465)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.os.Looper.loop(Looper.java:137)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.main(ActivityThread.java:4441)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at java.lang.reflect.Method.invoke(Method.java:511)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:0)

您忘记在片段布局中提及类而不是使用名称

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

答案 1 :(得分:0)

假设您已正确引用支持库和Google Play服务,代码正在运行。它显示了扇区32的块A.看看this如何在应用程序中包含地图。