Android等新手。
所以我推荐这个演示: http://dj-android.blogspot.in/2013/02/android-google-map-v2-part-1.html
我跟着它,但肯定出了问题。
...
...
...
当我在SGII v4.1.2上运行上面的项目时,我得到黑屏然后是crasj,然后是错误:
03-09 00:28:49.957: E/AndroidRuntime(20309): FATAL EXCEPTION: main
03-09 00:28:49.957: E/AndroidRuntime(20309): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapstest/com.example.mapstest.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.ActivityThread.access$700(ActivityThread.java:140)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.os.Looper.loop(Looper.java:137)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.ActivityThread.main(ActivityThread.java:4921)
03-09 00:28:49.957: E/AndroidRuntime(20309): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 00:28:49.957: E/AndroidRuntime(20309): at java.lang.reflect.Method.invoke(Method.java:511)
03-09 00:28:49.957: E/AndroidRuntime(20309): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-09 00:28:49.957: E/AndroidRuntime(20309): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
03-09 00:28:49.957: E/AndroidRuntime(20309): at dalvik.system.NativeStart.main(Native Method)
03-09 00:28:49.957: E/AndroidRuntime(20309): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-09 00:28:49.957: E/AndroidRuntime(20309): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.Activity.setContentView(Activity.java:1924)
03-09 00:28:49.957: E/AndroidRuntime(20309): at com.microsystools.mapstest.MainActivity.onCreate(MainActivity.java:17)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.Activity.performCreate(Activity.java:5206)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
03-09 00:28:49.957: E/AndroidRuntime(20309): ... 11 more
03-09 00:28:49.957: E/AndroidRuntime(20309): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-09 00:28:49.957: E/AndroidRuntime(20309): ... 21 more
03-09 00:28:49.957: E/AndroidRuntime(20309): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
03-09 00:28:49.957: E/AndroidRuntime(20309): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-09 00:28:49.957: E/AndroidRuntime(20309): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-09 00:28:49.957: E/AndroidRuntime(20309): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-09 00:28:49.957: E/AndroidRuntime(20309): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
03-09 00:28:49.957: E/AndroidRuntime(20309): ... 24 more
activity_main.xml中:
<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/fragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
MainActivity.Java
package com.example.mapstest;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.activity_main);
}
}
注1:
你们相信它可能是一个与API密钥有关的问题吗?我用它作为API密钥:
HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH;com.exampledomain.exampleproject
注2:
我当前配置的一些屏幕截图:
如果您认为我的问题的原因是Google Play服务未正确安装,我已在以下位置创建了单独的SO:Can not install google-play-services into Eclipse correctly (trying to get maps working)
答案 0 :(得分:4)
在参考文献库中我添加了“google-play-services.jar”
这是不正确的。请删除它。然后,将Play Services Android库项目导入Eclipse环境,并将其附加到项目中。
将/ extras / google / google_play_services / libproject / google-play-services_lib库项目复制到您维护Android应用项目的源树中。 如果您使用的是Eclipse,请将库项目导入工作区。点击文件&gt;导入,选择Android&gt;将现有的Android代码导入Workspace,并浏览到库项目的副本以导入它。
设置项目以使用Google Play服务SDK ...参考Android项目中的库项目。有关如何执行此操作的详细信息,请参阅Referencing a Library Project for Eclipse或Referencing a Library Project on the Command Line。
答案 1 :(得分:4)
试试这个:
这是我写的关于创建Google Map API V2的博文。
<强>更新强>
我从我的工作地图项目中拍了一张照片。忽略崩溃报告服务库,如acra,flurry,bugsense和crittercism。那么你投影的那些看起来是一样的吗?
您的 Android依赖关系文件夹中有google-play-services_lib.jar
吗?