0
我想將google地圖部署到我的android應用程序中。我遵循了我在這裏找到的一步一步的程序。但是,當我運行該應用程序。我被「不幸的是你的應用程序已停止錯誤。我跟着該文件中的每個步驟,請讓我知道錯誤。Android Google Map的演示應用程序 - 不幸停止
,這裏是我的logcat輸出
04-18 12:15:30.416: I/Process(1423): Sending signal. PID: 1423 SIG: 9
04-18 12:15:31.676: W/dalvikvm(1443): VFY: unable to resolve static field 2529 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-18 12:15:31.676: D/dalvikvm(1443): VFY: replacing opcode 0x62 at 0x000e
04-18 12:15:31.686: D/AndroidRuntime(1443): Shutting down VM
04-18 12:15:31.686: W/dalvikvm(1443): threadid=1: thread exiting with uncaught exception (group=0xb1a6cba8)
04-18 12:15:31.726: E/AndroidRuntime(1443): FATAL EXCEPTION: main
04-18 12:15:31.726: E/AndroidRuntime(1443): Process: tarun.ksr.mymap, PID: 1443
04-18 12:15:31.726: E/AndroidRuntime(1443): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Activity.onCreateView(Activity.java:4785)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Activity.setContentView(Activity.java:1929)
04-18 12:15:31.726: E/AndroidRuntime(1443): at tarun.ksr.mymap.MainActivity.onCreate(MainActivity.java:20)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Activity.performCreate(Activity.java:5231)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.os.Handler.dispatchMessage(Handler.java:102)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.os.Looper.loop(Looper.java:136)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-18 12:15:31.726: E/AndroidRuntime(1443): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 12:15:31.726: E/AndroidRuntime(1443): at java.lang.reflect.Method.invoke(Method.java:515)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-18 12:15:31.726: E/AndroidRuntime(1443): at dalvik.system.NativeStart.main(Native Method)
04-18 12:15:34.846: I/Process(1443): Sending signal. PID: 1443 SIG: 9
這裏是我的MainActivity.java
package tarun.ksr.mymap;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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 MainActivity extends Activity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
Marker ciu = mMap.addMarker(new MarkerOptions().position(CIU).title("My Office"));
}
@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;
}
}
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tarun.ksr.mymap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission>
<uses-permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCfVTb5mW1c-q8RdBtX7NJJ0S1KXgkHUP0"/>
<activity
android:name="tarun.ksr.mymap.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>
</application>
我補充,但我仍然收到錯誤。有一次它顯示致命的異常主要。另一次顯示谷歌播放服務已過時。我還檢查了我的SDK經理是否安裝了谷歌播放服務,也有任何更新可用。但我沒有找到任何更新。 –
作爲一個Android初學者,我因爲這些錯誤而感到沮喪。 –
你是如何將它添加爲庫項目或jar文件的? – AsG