我是Android开发的新手,但我还在学习并创建了一些简单活动的应用程序。但是这个需要我进行谷歌地图服务活动的应用程序无法由我执行。请查看代码并解释任何错误。我非常感谢你。
这里是清单代码
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<permission
android:name="com.example.googlemaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<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="in.csbuddy.aaas.Aaas"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAJJlKWPyQmwjfua1HV0fVHVkbN4Ny_iaw" />
</application>
和java代码
package in.csbuddy.aaas;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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;
public class Aaas extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_aaas);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.aaas, menu);
return true;
}
}
,布局文件如下:
<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=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
logcat的:
04-11 00:26:32.997: E/AndroidRuntime(22852): FATAL EXCEPTION: main
04-11 00:26:32.997: E/AndroidRuntime(22852): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Activity.onCreateView(Activity.java:4745)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Activity.setContentView(Activity.java:1895)
04-11 00:26:32.997: E/AndroidRuntime(22852): at in.csbuddy.aaas.Aaas.onCreate(Aaas.java:23)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Activity.performCreate(Activity.java:5133)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.access$600(ActivityThread.java:149)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.os.Looper.loop(Looper.java:137)
04-11 00:26:32.997: E/AndroidRuntime(22852): at android.app.ActivityThread.main(ActivityThread.java:5214)
04-11 00:26:32.997: E/AndroidRuntime(22852): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 00:26:32.997: E/AndroidRuntime(22852): at java.lang.reflect.Method.invoke(Method.java:525)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
04-11 00:26:32.997: E/AndroidRuntime(22852): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
04-11 00:26:32.997: E/AndroidRuntime(22852): at dalvik.system.NativeStart.main(Native Method)
04-11 00:26:32.997: W/ActivityManager(842): Force finishing activity in.csbuddy.aaas/.Aaas
每当我尝试跑步时,该应用程序都不会打开并显示&#34;不幸的是......&#34;错误。请帮帮我。
答案 0 :(得分:0)
您需要在清单文件中添加以下内容。
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
同样在您的build.gradle
for app中,您需要添加以下依赖项。
dependencies {
compile 'com.google.android.gms:play-services:7.8.0'
}
您也可以参考this post获取更多帮助!
希望这可以解决问题。