2013-10-07 17 views
0

我知道這個問題已經被問了很多次這裏,但沒有提供的解決方案的崩潰停止我的應用程序崩潰。應用程序與谷歌地圖時,我向FragmentActivity

這裏是在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; 
} 

} 

這裏是從佈局文件夾中的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: [email protected] attribute=null, token = [email protected] 

回答

1

庫沒有正確添加.. 檢查項目 - >右鍵單擊properties -.java build path -order和exprot select googleplayservices library。

+0

謝謝你回答我的問題:)我做了Java構建浴,訂單和出口,與Android的依賴文件夾選擇其中包含GOOGL eplayservices庫。該應用程序將無法啓動和logcat的是一樣的: –

+0

'代碼' 20 10-06:01:42.252:W/dalvikvm(3717):VFY:無法在LCOM /谷歌/ Android的解決靜態字段1358(MapAttrs)/克/ R $設置樣式; 10-06 20:01:42.252:D/dalvikvm(3717):VFY:在0x000e替換操作碼0x62 10-06 20:01:42.252:D/AndroidRuntime(3717):關閉VM 10-06 20: 01:42.252:W/dalvikvm(3717):線程ID = 1:螺紋與未捕獲的異常退出(組= 0x41fbf700) 10-06 20:01:42.262:E/AndroidRuntime(3717):致命異常:主 10-06 20:01:42.262:E/AndroidRuntime(3717):java.lang.NoClassDefFoundError:com.google.android.gms.R $設置樣式 '代碼' –

-1

我的代碼工作中的編輯像下面和導入谷歌圖書館的方式,

 android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" 
相關問題