3

New to Android etc.

So I was recommended this demo: http://dj-android.blogspot.in/2013/02/android-google-map-v2-part-1.html

I followed it, but something must have gone wrong.

...

  • In workspace I have my own project:
  • Inside this project: In "Libs" I have added "android-support-v4.jar"
  • Inside this project: In Android Depencides I have "android-support-v4.jar"
  • Inside this project: In References Libraries I have "google-play-services.jar"
  • Inside this project: In References Libraries I have "android-support-v4.jar"

...

  • In workspace I have google-play-services_lib as a project:
  • Inside this project: In "Libs" I have "google-play-services.jar"
  • Inside this project: In "Libs" I have "google-play-services.jar.properties"
  • Inside this project: In "Android Dependencies" I have "google-play-services.jar"

...

When I run above project on SGII v4.1.2 I get black screen followed by crasj followed by error:

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);  
       }  
  }    

NOTE 1:

Do you guys belive it can be a problem related to the API key somehow? I use this as API key:

HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH:HH;com.exampledomain.exampleproject
  • Notice the ending. Is that correct?
  • I had to edit the output from keytool, so not 100% sure the API key is good. See: Maps v2 API Key on Android

NOTE 2:

Some screenshots of my current configuration:

enter image description here enter image description here

If you believe the cause of my problems is that Google Play Services is not installed correctly, I have created a separate SO for that at: Can not install google-play-services into Eclipse correctly (trying to get maps working)

Community
  • 1
  • 1
Tom
  • 3,587
  • 9
  • 69
  • 124

2 Answers2

4

In References Libraries I have added "google-play-services.jar"

That is incorrect. Please remove that. Then, import the Play Services Android library project to your Eclipse environment, and attach it to your project.

Quoting the documentation:

Copy the /extras/google/google_play_services/libproject/google-play-services_lib library project into the source tree where you maintain your Android app projects. If you are using Eclipse, import the library project into your workspace. Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.

To set up a project to use the Google Play services SDK... Reference the library project in your Android project. See the Referencing a Library Project for Eclipse or Referencing a Library Project on the Command Line for more information on how to do this.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks. However, That did not change the error :( (I am kinda puzzled why google-play-services.jar has be part of work-space and can not be part of the project like the support libraries. But noww I have tried it both ways!) – Tom Mar 08 '13 at 23:30
  • 1
    @Tom: "I am kinda puzzled why google-play-services.jar has be part of work-space and can not be part of the project like the support libraries." -- because it isn't just a JAR. It is an Android library project, which includes Android resources. – CommonsWare Mar 08 '13 at 23:33
4

Try this one:

link

it's a blog post i wrote on creating a Google Map API V2.

UPDATE:

enter image description here

I took a picture from my working map project. ignore the crash reporting services libs like acra, flurry, bugsense and crittercism. other then those you project looks the same?

do you have google-play-services_lib.jar in your Android Dependencies folder?

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • While I can not see the class code on how you load the XML, I tried it, but I can the same error as in my original post. I have now added the full log. – Tom Mar 09 '13 at 00:18
  • 1
    if you look carefully at the post you see this: "8. Now create an Activity that extends from “FragmentActivity” , create an XML layout file for this activity and set it as the content View of this activity, in the layout write the following:" So for the class what you need to do is create a simple activity that extends FragmentActivity and set the discribed layout as setContentView (R.layout.maplayout) – Emil Adz Mar 09 '13 at 14:21
  • 1
    Tom: from the error you receive: "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", clearly you are doing something wrong with referencing the google-play-services project. are you positive you followed the first 4 steps of the guide correctly? – Emil Adz Mar 09 '13 at 20:06
  • The only thing left I can think of is the API key is somehow wrong. And that then gives error uopon inflating the XML. Is that possible? I have edited this SO with a link to another SO I made about the API key, and if what I had to do was normal keytool behavior (the output looked different than what I expeced with garbage between the hex characters) Still if that was the problem, I would have expected an error about the API key... – Tom Mar 09 '13 at 20:08
  • 1
    if you key is not good there will not be a problem in inflating the mapFragment. you will see a blank map window with zoom controls but you wont receive this error. that the reason I think you are doing some thing wrong with the google-play-services project library. did you added it to your work-space and then referenced it from your project as it described in the guide? – Emil Adz Mar 09 '13 at 20:16
  • I have just edited this post at top with complete reference over where the libraries (both support and google play) are references in my project + workspace. – Tom Mar 09 '13 at 20:44
  • Well, when I do *exactly* like your guide, I get a red cross instead of a green marker. I will post screenshots along the way. Give me 5 mins. – Tom Mar 10 '13 at 11:05
  • I have now posted screenshots that show my current setup + what I get when trying to add google-play-services as you describe. (The interesting thing is that when I first add it, I do get green marker, but when I get back, it is the red cross from the screenshot. Plus "google-play-services.jar" has not been added to "Android Dependencies") – Tom Mar 10 '13 at 11:11
  • 1
    now you see what your problem is... try to download the last SDK again and then go to the SDK manager and download the last version of google-play-services at extras section. then do all the process of adding this project from: \extras\google\google_play_services\libproject\google-play-services_lib from where you download your sdk updates to your workspace. when you fix the red X to a green V and the google-play-services_lib.jar will be added to your Android Dependencies it should work. – Emil Adz Mar 10 '13 at 12:05
  • I (already) downloaded and (re)-installed entire Eclipse + all possible modules 3 days ago :( But will try again, and see if there is anything I can do. Will be back when I have more info. – Tom Mar 10 '13 at 17:46
  • It seems I still can't. 8What you describe is also what I did around 3 days ago anyhow so...) I have tried searching the net for similar cases to mine, but no solutions appear to have been found for those people :( I tried searching for "google_play_services red cross" and similar – Tom Mar 10 '13 at 17:59
  • 1
    @Tom, the only time that i encounter this problem (Red X) is when I try to move a map project from one computer to another and the google-play-services_lib is not located in the same place so I have to re-do the referencing each time i move the project. but after that the red X becomes green V again. So I am sorry but I have no idea why this is happening to you, I tried to help you with what I know. – Emil Adz Mar 10 '13 at 19:18
  • Hi Emil: I really appreciate your effort. I will post if I get new information. For now I have posted a new SO as well: http://stackoverflow.com/questions/15325654/can-not-install-google-play-services-into-eclipse-correctly-trying-to-get-maps – Tom Mar 11 '13 at 11:30
  • The solution ended being... Make a copy of the google-play-services lib and move it to different localtion (maybe less long path?) ... And then it worked... OMG – Tom Mar 13 '13 at 20:36
  • maybe... glad you figured it out, have a nice coding. – Emil Adz Mar 13 '13 at 23:44