我要加载的谷歌地图API在我的机器人。我尝试一切,我搜索,但它仍然崩溃。 这是我的MainActivity.java
包com.example.androidmapsv2;
进口android.os.Bundle;
进口android.support.v4.app.FragmentActivity;
进口com.google.android.gms.common.GooglePlayServicesUtil;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.SupportMapFragment;
公共类MainActivity扩展FragmentActivity {
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
//显示操作栏中的向上按钮。
getActionBar()setDisplayHomeAsUpEnabled(真)。
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
使用GoogleMap地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
}
}
这是我的布局activity_main.xml
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.SupportMapFragment/>
< / RelativeLayout的>
这是我的清单
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.androidmapsv2
安卓版code =1
机器人:VERSIONNAME =1.0>
<用途-SDK
安卓的minSdkVersion =11
机器人:targetSdkVersion =16/>
<许可
机器人:名称=com.example.androidmapsv2.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名>
< /许可>
<使用-权限的Android:名称=com.example.androidmapsv2.permission.MAPS_RECEIVE/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
<使用-权限的Android:名称=android.permission.ACCESS_FINE_LOCATION/>
<! - 要求的OpenGL ES版本2 - >
<用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/>
<应用
机器人:allowBackup =真
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<使用库机器人:名称=com.google.android.maps/>
<活动
机器人:名称=com.example.androidmapsv2.MainActivity
机器人:标签=AAA>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
&所述;元数据
机器人:名称=com.google.android.maps.v2.API_KEY
机器人:值=AIzaSyDr9xN8L3sF6W2ZRWmTR7q0lhTeOWhXEfQ/>
< /用途>
< /舱单>
这是我已经拿到了钥匙
这是包含在库(更新中解决)
和我没有一个真正的Android设备,所以我在此教程
这是logcat的
01-09 18:05:19.184:E /跟踪(1366):错误打开跟踪文件:没有这样的文件或目录(2)
01-09 18:05:19.354:W / dalvikvm(1366):无法解析LCOM的超/例子/ androidmapsv2 / MainActivity; (5)
01-09 18:05:19.354:W / dalvikvm(1366):Link类的LCOM /例子/ androidmapsv2 / MainActivity;失败
01-09 18:05:19.365:D / AndroidRuntime(1366):关闭虚拟机
01-09 18:05:19.365:W / dalvikvm(1366):主题ID = 1:螺纹退出与未捕获的异常(组= 0x40a13300)
01-09 18:05:19.384:E / AndroidRuntime(1366):致命异常:主要
01-09 18:05:19.384:E / AndroidRuntime(1366):java.lang.RuntimeException的:无法实例活动ComponentInfo {com.example.androidmapsv2 / com.example.androidmapsv2.MainActivity}:抛出java.lang.ClassNotFoundException:COM .example.androidmapsv2.MainActivity
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.ActivityThread.access $ 600(ActivityThread.java:130)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1195)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.os.Handler.dispatchMessage(Handler.java:99)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.os.Looper.loop(Looper.java:137)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 18:05:19.384:E / AndroidRuntime(1366):在java.lang.reflect.Method.invokeNative(本机方法)
01-09 18:05:19.384:E / AndroidRuntime(1366):在java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:05:19.384:E / AndroidRuntime(1366):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 18:05:19.384:E / AndroidRuntime(1366):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 18:05:19.384:E / AndroidRuntime(1366):在dalvik.system.NativeStart.main(本机方法)
01-09 18:05:19.384:E / AndroidRuntime(1366):抛出java.lang.ClassNotFoundException:产生的原因com.example.androidmapsv2.MainActivity
01-09 18:05:19.384:E / AndroidRuntime(1366):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-09 18:05:19.384:E / AndroidRuntime(1366):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-09 18:05:19.384:E / AndroidRuntime(1366):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-09 18:05:19.384:E / AndroidRuntime(1366):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
01-09 18:05:19.384:E / AndroidRuntime(1366):11 ...更多
更新时间:
我试图复制谷歌的播放,services_lib到工作区和红色标记消失 但来了另一个错误。它错过了谷歌播放的,services_lib.jar(lib文件夹名称+的.jar)。如何解决 当我点击谷歌的播放,services_lib.jar,删除按钮显示不出来(如照片)。但是我尝试删除所有的Android的依赖,并导入其他人再次LIB。现在它的工作,但还是崩溃。
我试着改变
MainActivity延伸活动
要
MainActivity延伸FragmentActivity
和布局
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.SupportMapFragment/>
< / RelativeLayout的>
它出现另一个错误。帮我,现在我出的解决方案,这个
最后,我解决我的错误。这引起我的Eclipse(我猜)。当您添加库类,它会自动出现谷歌播放services_lib.jar,你不必做任何事情。我重新安装Eclipse和一切工作正常
解决方案我也面临着这样的问题,当第一次编码与API V2地图。
而不是活动刚刚尝试使用带有 FragmentActivity
的延伸
您必须将项目(goolge_play_services)复制到你的工作区,然后将其连接到您的项目。在上面的图片显示它的红十字,所以选择它,删除,然后再经过一次加附加库项目。
I want to load the google map API on my android. I try everything I search but it still crash. this is my MainActivity.java
package com.example.androidmapsv2;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
This is my layout activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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.SupportMapFragment"/>
</RelativeLayout>
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidmapsv2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<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="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="android.permission.ACCESS_FINE_LOCATION" />
<!-- Require OpenGL ES version 2 -->
<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" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.androidmapsv2.MainActivity"
android:label="aaa" >
<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="AIzaSyDr9xN8L3sF6W2ZRWmTR7q0lhTeOWhXEfQ" />
</application>
</manifest>
This is the key i've got
This is the libs included (Solved in update)
and i don't have a real android device, so i install it on emulator in this tutorial
This is the logcat
01-09 18:05:19.184: E/Trace(1366): error opening trace file: No such file or directory (2)
01-09 18:05:19.354: W/dalvikvm(1366): Unable to resolve superclass of Lcom/example/androidmapsv2/MainActivity; (5)
01-09 18:05:19.354: W/dalvikvm(1366): Link of class 'Lcom/example/androidmapsv2/MainActivity;' failed
01-09 18:05:19.365: D/AndroidRuntime(1366): Shutting down VM
01-09 18:05:19.365: W/dalvikvm(1366): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-09 18:05:19.384: E/AndroidRuntime(1366): FATAL EXCEPTION: main
01-09 18:05:19.384: E/AndroidRuntime(1366): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.androidmapsv2/com.example.androidmapsv2.MainActivity}: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.os.Looper.loop(Looper.java:137)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:05:19.384: E/AndroidRuntime(1366): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 18:05:19.384: E/AndroidRuntime(1366): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.NativeStart.main(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): Caused by: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
01-09 18:05:19.384: E/AndroidRuntime(1366): ... 11 more
UPDATED
i've tried to copy the google-play-services_lib to workspace and red mark disappear but it come another error. It missing the google-play-services_lib.jar (the lib folder name + .jar). how to fix it when i click the google-play-services_lib.jar, the remove button doesn't show up(like picture). However i try remove all Android Dependencies and import the others lib again. now it working, but still crash.
I've tried change
MainActivity extends Activity
To
MainActivity extends FragmentActivity
and the layout
<?xml version="1.0" encoding="utf-8"?>
<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.SupportMapFragment"/>
</RelativeLayout>
it appear another error. help me, now i'm out of solution for this
Finally, i solved my error. It caused by my eclipse (i guess). When you add the library class, it automatically appear "google-play-services_lib.jar", you don't have to do anything. I reinstall Eclipse and everything work fine
解决方案I also faces this kind of the problem,when first time coding for the map with API V2.
Just try using the extends with FragmentActivity
instead of the Activity
you have to copy the project(goolge_play_services) into your workspace and then attach it to your project. In above image it show the cross red,so select it and remove and then after once again add attach the library with the project.