Я изучаю разработку Android с помощью видеоинструкции lynda.
Я добавляю Google-Play-сервисы для создания карт. я сделал согласно учебнику, eclipse не показывал никаких ошибок, но когда я пытаюсь запустить его на эмуляторе и моем устройстве. он дает ошибку, к сожалению, Mymaps остановился.
Я добавил ошибку и мой код ниже. может ли кто-нибудь сказать мне, как закончить эту ошибку. Спасибо.
ошибка
01-28 14:04:55.650: D/AndroidRuntime(1045): Shutting down VM
01-28 14:04:55.693: W/dalvikvm(1045): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
01-28 14:04:55.730: E/AndroidRuntime(1045): FATAL EXCEPTION: main
01-28 14:04:55.730: E/AndroidRuntime(1045): java.lang.RuntimeException: Unable to start activity ComponentInfo{lk.adspace.jaffnatemples/lk.adspace.jaffnatemples.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.os.Looper.loop(Looper.java:137)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-28 14:04:55.730: E/AndroidRuntime(1045): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 14:04:55.730: E/AndroidRuntime(1045): at java.lang.reflect.Method.invoke(Method.java:511)
01-28 14:04:55.730: E/AndroidRuntime(1045): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-28 14:04:55.730: E/AndroidRuntime(1045): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-28 14:04:55.730: E/AndroidRuntime(1045): at dalvik.system.NativeStart.main(Native Method)
01-28 14:04:55.730: E/AndroidRuntime(1045): Caused by: java.lang.IllegalStateException: The meta-data tag in your app AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
01-28 14:04:55.730: E/AndroidRuntime(1045): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-28 14:04:55.730: E/AndroidRuntime(1045): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-28 14:04:55.730: E/AndroidRuntime(1045): at lk.adspace.jaffnatemples.MainActivity.servicesOK(MainActivity.java:44)
01-28 14:04:55.730: E/AndroidRuntime(1045): at lk.adspace.jaffnatemples.MainActivity.onCreate(MainActivity.java:23)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.Activity.performCreate(Activity.java:5104)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-28 14:04:55.730: E/AndroidRuntime(1045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-28 14:04:55.730: E/AndroidRuntime(1045): ... 11 more
мой код для main_activity (java файл)
package lk.adspace.jaffnatemples;
import lk.adspace.jaffnatemples.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(servicesOK()){
Toast.makeText(this, "Ready for mapping! baman", Toast.LENGTH_SHORT).show();
}
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;
}
public boolean servicesOK(){
int isAvaliable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(isAvaliable == ConnectionResult.SUCCESS){
return true;
}else if (GooglePlayServicesUtil.isUserRecoverableError(isAvaliable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvaliable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}else {
Toast.makeText(this, "Cant connect to google paly services", Toast.LENGTH_SHORT).show();
}
return false;
}
}
мой файл манифеста
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lk.adspace.jaffnatemples"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="lk.adspace.jaffnatemples.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="lk.adspace.jaffnatemples.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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="lk.adspace.jaffnatemples.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="AIzaSyg7tc1ux10tYAgv6hgydfZ4BspLzhRKhld5"/>
</application>
</manifest>
///вам нужно добавить эту строку также в свой манифест. xml
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
//и вам нужно добавить эту строку ниже в папку значений в string.xml
или integer.xml
<integer name="google_play_services_version">4132500</integer>
java.lang.RuntimeException ...
) говорит вам точно, в чем проблема