0

我知道这个问题已经在这里被问过很多次了,但是提供的解决方案都没有阻止我的应用程序崩溃。

这是我在 MainActivity 中的代码:

package com.example.gpstracking2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
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.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Marker;

public class MainActivity extends FragmentActivity {

GoogleMap googleMap;

Marker marker = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

以下是 layout 文件夹中 activity_main.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"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /> 
</LinearLayout>

这是清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpstracking2"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<permission android:name="com.example.gpstracking2.permission.MAPS_RECEIVE"   android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gpstracking2.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" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.gpstracking2.MainActivity"
        android:label="@string/app_name" >
        <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="KEY"/>
</application>

</manifest>

这是logcat:

10-06 16:57:27.966: W/dalvikvm(6735): VFY: unable to resolve static field 1346    (MapAttrs) in Lcom/google/android/gms/R$styleable;
10-06 16:57:27.966: D/dalvikvm(6735): VFY: replacing opcode 0x62 at 0x000e
10-06 16:57:27.966: D/AndroidRuntime(6735): Shutting down VM
10-06 16:57:27.966: W/dalvikvm(6735): threadid=1: thread exiting with uncaught exception (group=0x41df3700)
10-06 16:57:27.966: E/AndroidRuntime(6735): FATAL EXCEPTION: main
10-06 16:57:27.966: E/AndroidRuntime(6735): java.lang.NoClassDefFoundError:   com.google.android.gms.R$styleable
10-06 16:57:27.966: E/AndroidRuntime(6735):     at   com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:284)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.Activity.setContentView(Activity.java:1895)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at com.example.gpstracking2.MainActivity.onCreate(MainActivity.java:25)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.Activity.performCreate(Activity.java:5133)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.os.Looper.loop(Looper.java:137)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at java.lang.reflect.Method.invokeNative(Native Method)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at java.lang.reflect.Method.invoke(Method.java:525)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-06 16:57:27.966: E/AndroidRuntime(6735):     at dalvik.system.NativeStart.main(Native Method)
10-06 16:57:27.976: W/ActivityManager(428):   Force finishing activity com.example.gpstracking2/.MainActivity
10-06 16:57:28.056: D/dalvikvm(428): GC_FOR_ALLOC freed 2309K, 20% free 17147K/21256K, paused 68ms, total 68ms
10-06 16:57:28.566: W/ActivityManager(428): Activity pause timeout for ActivityRecord{42889d90 u0 com.example.gpstracking2/.MainActivity}
10-06 16:57:28.616: I/ActivityManager(428): No longer want com.android.defcontainer (pid 5432): empty #17
10-06 16:57:29.876: I/Process(6735): Sending signal. PID: 6735 SIG: 9
10-06 16:57:29.876: I/ActivityManager(428): Process com.example.gpstracking2 (pid 6735) has died.
10-06 16:57:29.896: W/InputMethodManagerService(428): Window already focused, ignoring   focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4266be70   attribute=null, token = android.os.BinderProxy@425f0da8
4

2 回答 2

1

库未正确添加..检查项目->右键单击属性-.java构建路径-顺序并导出选择googleplayservices库。

于 2013-10-07T02:45:02.560 回答
-1

我的代码正在以如下方式编辑并导入谷歌库,

     android:id="@+id/map"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     class="com.google.android.gms.maps.SupportMapFragment" 
于 2013-10-07T06:50:14.730 回答