劲舞团date 121.acv/061.acv Can't make MapView File!(Init)给我发下好...

Your antique browser is not supported!Your antique browser is not supported!Your client is incapable of displaying standards-compliant web pages, and I do not have the resources to continue supporting antiquated browsers.If you wish to view this web site, you will need to upgrade to a better browser, like these are..Unable instantiate android.gms.maps.MapFragment - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I try to do a demo with google maps android v2 with very simple actitiviy, just copy code from google page:
for activity:
package com.example.
import android.app.A
import android.os.B
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
for layout:
&?xml version="1.0" encoding="utf-8"?&
&fragment xmlns:android="/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/&
I had apply for a api key according to page and modify my androidmanifest.xml file, just like this:
&manifest xmlns:android="/apk/res/android"
package="com.wenhai.driverschool"
android:versionCode="1"
android:versionName="1.0" &
android:minSdkVersion="8"
android:targetSdkVersion="15" /&
&uses-permission android:name="android.permission.INTERNET" /&
&!-- add for map2 --&
&permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" /&
&uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" /&
&uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&
&!-- External storage for caching. --&
&uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&
&!-- Maps API needs OpenGL ES 2.0. --&
&uses-feature
android:glEsVersion="0x"
android:required="true" /&
&application
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="AIzaSyDVAF4WaVSVRDKJx87It8OSFP5txQcPabc" /&
android:name=".MainActivity"
android:label="@string/title_activity_main" &
&intent-filter&
&action android:name="android.intent.action.MAIN" /&
&category android:name="android.intent.category.LAUNCHER" /&
&/intent-filter&
&/activity&
&/application&
&/manifest&
I also reference my app to google-play-services_lib in eclipse.
but everytime, error report in logcat like this:
2-05 16:22:53.609: E/AndroidRuntime(21623): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wenhai.driverschool/com.wenhai.driverschool.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.os.Looper.loop(Looper.java:137)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.ActivityThread.main(ActivityThread.java:4441)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at java.lang.reflect.Method.invoke(Method.java:511)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at dalvik.system.NativeStart.main(Native Method)
12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Activity.setContentView(Activity.java:1835)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at com.wenhai.driverschool.MainActivity.onCreate(MainActivity.java:11)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Activity.performCreate(Activity.java:4465)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
12-05 16:22:53.609: E/AndroidRuntime(21623):
... 11 more
12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Fragment.instantiate(Fragment.java:581)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Fragment.instantiate(Fragment.java:549)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Activity.onCreateView(Activity.java:4235)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
12-05 16:22:53.609: E/AndroidRuntime(21623):
... 20 more
12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
12-05 16:22:53.609: E/AndroidRuntime(21623):
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-05 16:22:53.609: E/AndroidRuntime(21623):
at android.app.Fragment.instantiate(Fragment.java:571)
12-05 16:22:53.609: E/AndroidRuntime(21623):
... 23 more
I don't know the reason for this.
If i add google-play-services.jar into my project, it will report another error:
12-05 16:34:23.269: E/AndroidRuntime(22638): FATAL EXCEPTION: main
12-05 16:34:23.269: E/AndroidRuntime(22638): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
12-05 16:34:23.269: E/AndroidRuntime(22638):
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.Activity.onCreateView(Activity.java:4242)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.Activity.setContentView(Activity.java:1835)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at com.wenhai.driverschool.MainActivity.onCreate(MainActivity.java:11)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.Activity.performCreate(Activity.java:4465)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.os.Looper.loop(Looper.java:137)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at android.app.ActivityThread.main(ActivityThread.java:4441)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at java.lang.reflect.Method.invoke(Method.java:511)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
12-05 16:34:23.269: E/AndroidRuntime(22638):
at dalvik.system.NativeStart.main(Native Method)
Anyone can help me about this?
thank you very much.
In IntelliJ IDEA (updated for IntelliJ 12):
Create a file ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/src/dummy.java containing class dummy {}.
File->Import Module-> ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib
Create Module from Existing Sources
Next->Next->Next->Next->Finish
File->Project Structure->Modules->YourApp
+->Module Dependency->Google-play-services_lib
(The + button is in the top right corner of the dialog.)
+->Jars or directories->~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
Use the up/down arrows to move &Module source& to the bottom of the list.
You can delete dummy.java if you like.
Edit: After using this for a while I've found that there is a small flaw/bug. IDEA will sometimes complain about not being able to open a .iml project file in the google-play-services_lib directory, despite the fact that you never told it there was a project there. If that happens, rebuilding the project solves the problem, at least until it comes back.
16.5k23108180
20.7k19131147
Please follow Commonsware MapV2 code snippets to get better understanding.
(It is present in Omnibus edition)
Following snippet is working fine at my end.I choose to use SupportMapFragment.
Dont forget to add google-play-services.jar into your project.
MainActivity.java
package com.example.
import android.os.B
import android.support.v4.app.FragmentA
import com.google.android.gms.maps.SupportMapF
public class MainActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
manifest.xml
&?xml version="1.0" encoding="utf-8"?&
&manifest xmlns:android="/apk/res/android"
package="com.example.newmapview"
android:versionCode="1"
android:versionName="1.0" &
android:minSdkVersion="8"
android:targetSdkVersion="16" /&
&permission
android:name="com.example.newmapview.permission.MAPS_RECEIVE"
android:protectionLevel="signature" /&
&uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" /&
&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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&
&application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" &
android:name="com.example.newmapview.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="XXXXX" /&
&/application&
&uses-feature
android:glEsVersion="0x"
android:required="true" /&
&/manifest&
Here is the result
Hope this will help.
20.4k64366
Just try to replace your layout with :
&?xml version="1.0" encoding="utf-8"?&
&fragment xmlns:android="/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" /&
You need to use the SupportMapFragment for API under 11 !
I faced the same problem ant it took me tow days to figure out a solution
that worked for me :
Delete the project google-play-services_lib (right click on the project delete )
Delete the project containing the Google maps demo ( MainActivity in my case ) if you have one
project google-play-services_lib( extras\google\google_play_services\libproject\google-play-services_lib) into your workspace then import it as General project
(File->import->existing projects into workspase
Right click on your project ( in which you want to load the map ) -> Android -> add (under library ) google-play-services_lib
You should see something like this :
Note : You should not have something
like this ( the project should be referred from your workspace ):
I think that the problem is that tow projects are referencing the same library
3,24332248
I just added the project of google services and added a reference in my project property->Android
By now, demo can work follow :
For example demo, it can work too:
Add two jar in libs directory in your project. Follow below information. In particular, I think you need to:
Import the actual source for the "google-play-services_lib" project and link it as an Android library.
Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.
Add the google-play-services.jar and android-support-v4.jar into a "libs" folder in the sample project, and add them as "External External JARs" in "Build Path -> Configure Build Path -> Libraries".
I found this second step was necessary as I was hitting the exact same error as you when trying to use the sample code. The first step was necessary to avoid a NoClassDefFoundError in com.google.android.gms.R$styleable in my real project.
I also needed to do a Clean build and Uninstall the app from the device (from an earlier test attempt) before the sample code worked.
thanks your help very much.
18.8k74470
Maybe You must highlight this :
Note: Google Play services is not supported on the Android emulator -- to develop using the APIs, you need to provide a development device such as an Android phone or tablet.
You must provide a physical development device on which you can run and debug your app. Do not use emulator. Will not working.
In your MainActivity (or in each activity you want to put the v2 map) you must extend FragmentActivity or Activity either you want to use SupportMapFragment or just MapFragment. Use MapFragment class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment. It's a subtle difference but it makes the error.
23.2k144580
As Google map is wrapped under Fragments now, extend your activity from FragmetActivity not just Activity and make sure if you use "supporrtMapFragment" then you are importing Fragment from support package only.
I have the same problem and I'm searching the solution. If I fix this I turn to post here. However, you can try to debug in a mobile device.
In my Intellij Idea project I had to add both: google-play-services_lib and google-play-services.jar to the project. And in google-play-services_lib project add google-play-services.jar too. After that, if you did all things, that described , right, your application should be working.
1,18111328
It was a little difficult because it was different in the previous API, but I found a solution.
Goo according with the question we need com.google.android.gms classes so it is necessary to setup the google play services, which is just a library that we have to add to our project like this
. It's very important to import the copy of the project library google-play-services_lib not the one that is in the sdk folder. Once that's done, the tutorial from Google goes perfectly.
7,855114871
relate to this suggestion :
also i had to add this to Application element in the Manifest:
&meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /&
and it worked perfectly.
Add this dependency in build.gradle
compile 'com.google.android.gms:play-services:6.5.87'
Now this works
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"&
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="388dp"
android:layout_weight="0.40" /&
&/LinearLayout&
To take care of the Drive-related imports, you'll need a few jars from the Google Drive SDK. There are a few large ones, so you may want to add them individually to suit your app.
If that doesn't resolve the com.google.android.gms.* imports, the Google Play Services add-on needs to be installed (from Extras -& Google Play Services in the SDK Manager) and google-play-services.jar needs to be added to your build path.
In this case, the following jars were needed:
google-api-services-drive-v2-rev1-1.7.2-beta.jar
google-http-client-1.10.3-beta.jar
google-http-client-android2-1.10.3-beta.jar
google-oauth-client-1.10.1-beta.jar
google-api-client-android2-1.10.3-beta.jar
google-api-client-1.10.3-beta.jar
16.2k105287
I had the same problem on my LG-E730 with 2.3.4 Android.
The error appears before I've updated
on my phone.
Do not forget to actually build the google-play-services_lib!! That's why it shows the "Could not find google-play....apk". For me, on Eclipse, no other hacks were needed, but to reference the project from the Android submenu, not from Java build path, or Project references or whatever else. No manually placed jars, no nothing were actually needed for me.
In Eclipse, it is necessary to create a separate project for google play services and reference it as a lib from your Android project instead of simply adding the jar to it. In my computer I have imported the google play services Eclipse project directly from D:\adt-bundle-windows-x86-\sdk\extras\google\google_play_services\libproject\google-play-services_lib and set it to Lib project so I could reference it from my Android project.
It is stated on the same tutorial that
Please note that the code below is only useful for testing your
settings in an application targeting Android API 12 or later
Just change your min SDK version to 12 and it will works
android:minSdkVersion="8"
android:targetSdkVersion="15" /&
Haven's tried Aurel's workaround for older versions of the API yet.
1,54832251
I think it is worth mentioning (after I spent over an hour pulling out my hair) that if you are using MapFragment you cannot use FragmentActivity (SupportMapFragment will function fine in this environment).
I was just about ready to give up on it.
First Step
Second Step
On that page it has a NOTE but we didn't pay attention
Note: You should be referencing a copy of the library that you copied to your source tree--you should not reference the library from the Android SDK directory.
But I think it's not a good way of documentation :)
This might be of help to some.
I had two projects, one which was a copy of the demo from Google and that worked fine.
Another I copied into an existing project and I could not get it to run at all.
And in the second failing one I was getting the error message described above.
My problem was due to a library not enabled, even though I rebuilt, imported multiple times etc.
Right-click on the project -> Properties -> Java Build Path -> Order & Export tab.
On the failing project the "Android Private Libraries" tab was unchecked.
Once I enabled it the project worked fine.
Apart from many of the things mentioned before, to me it was important to mark the .jar also in Order and Export. As far as I can tell, is not usually mentioned and to me it was crucial.
1,71621838
i had everything what everyone above was saying and resolved the error by simply calling the
super.onCreate(savedInstanceState); as first instructio before it was last line in method. :|
wasted whole day.
I've this issue i just update Google Play services and make sure that you are adding the google-play-service-lib project as dependency, it's working now without any code change but i still getting "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included." but this only happens when you have setMyLocationEnabled(true), anyone knows why?
I don't get the true solution but I solve it after doing these things:
- Tick 'Copy projects into workspace' when importing google-play-services_lib
- Don't set the minSdkVersion below 13
- If you get error with theme, try changing your layout theme to any system theme
- Re-create your project from scratch or revert everything if you get it from somewhere
I got the same problem and just Installed Play Services from SDK and all problems fly away.
I wrote in the activity
import com.google.android.gms.maps.SupportMapF
and Eclipse gave me the red icon > click > fix projec setup.. > add archive google-play-services.jar
And finnaly it worked!!
Add Google Play Services to Your Project
To make the Google Play services APIs available to your app:
follow the steps present in this link :
I faced this issue while using Android SDK for x86 in a Windows 7 64-bit machine. I downloaded the Android SDK 64-bit version, made Eclipse see it in Window > Preferences > Android > SDK location and the issue stopped occurring.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

参考资料

 

随机推荐