Empty Detail's fragment in Example from Android Developers

322 views
Skip to first unread message

lomza_t

unread,
Aug 7, 2011, 3:22:28 PM8/7/11
to Android Compatibility Library for Google Maps - Support
Hi, Pete!
I was very happy to find out that there is a possibility to build a
Map into the Fragment. Thanks to You!!!
But, I've encountered some problems using Your port of 'android-
support-v4-googlemaps' package. Currently, I use an example code of
Fragments from Android Developers site:
http://developer.android.com/guide/topics/fundamentals/fragments.html
The problem is - when I run the project, on Android tablet emulator,
only list is displayed. Clicking on the list, does not make any
effect. In XML-layout I see this text: "The following classes could
not be instantiated:
- (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when
shown in Eclipse"
In Error Log:

java.lang.ClassNotFoundException: com.google.android.maps.MapActivity
at
com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader.findClass(ProjectClassLoader.java:
94)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader.loadFromProject(ProjectClassLoader.java:
136)
at
com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader.findClass(ProjectClassLoader.java:
84)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at
com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:
321)
at
com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:
164)
at android.app.Fragment_Delegate.instantiate(Fragment_Delegate.java:
72)
at android.app.Fragment_Delegate.instantiate(Fragment_Delegate.java:
52)
at android.app.Fragment.instantiate(Fragment.java:468)
at android.app.Activity.onCreateView(Activity.java:4081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:
659)
at
com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:
128)
at
android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:
76)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at android.view.LayoutInflater.inflate(LayoutInflater.java:367)
at
com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:
315)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:314)
at
com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:
325)
at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:
380)
at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:
1310)
at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:
1075)
at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:
901)
at
com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange(LayoutEditor.java:
403)
at org.eclipse.ui.part.MultiPageEditorPart
$2.widgetSelected(MultiPageEditorPart.java:290)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:
234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:
2743)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1429)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:
257)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:
2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:
332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:
664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:
149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:
115)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:
196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:
110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:
79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
369)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)

Is it because I extend the Fragment, not FragmentActivity in
DetailsFragment class? Though, the app is compatible with phone
versions...
I really don't know how I can solve the problem.

If the source code will help, its here: http://codeviewer.org/view/code:1d5d
Thanks in advance!

Pete Doyle

unread,
Aug 7, 2011, 5:28:02 PM8/7/11
to android-support-v4...@googlegroups.com
Hi Tonia,
Make sure your Android manifest has <uses-library android:name="com.google.android.maps" /> somewhere inside the <application></application> tag.  More details here:

Also, make sure your eclipse project is set to use a "Google APIs" target.  (Right click your project in Eclipse's Project Explorer, go to Android, and set the Project Build Target).  I'm currently targeting Google APIs level 13 (Android 3.2), but I think it should work back to Google APIs level 4 (Android 1.6).

Let me know if you run into any more issues.  There's a lot of hacks you'll end up needing.  I need to make a sample project, but I haven't taken the time yet.

P.S. Make sure to go star this android issue so maybe someday we can have a real MapFragment. :)

Thanks,
Pete

lomza_t

unread,
Aug 8, 2011, 5:13:54 AM8/8/11
to Android Compatibility Library for Google Maps - Support
Hi, Pete!

Thanks for Your reply!
I double-checked the Manifest, and it's OK.
I have tried to use the compatibility package at work and it works!
Though, there is the same error notification in .xml layout. Magic!

Another thing, is when I just created a project from the package
You've posted on GitHub, I've got some errors in ViewGroup, so I added
3 libraries to it, to make it work: android-13.jar, maps-13.jar and
android-support-v13.jar. Then I add this project to my project's Build
Path, run it and got the error, I've described above. I also tried to
create a simple project with MapView built in a Fragment, but it
failed... Can You, please, tell me the concept? I must have an
activity which extends FragmentActivity and in .xml layout I can simpy
built the MapView inside a <fragment>, is this correct?

Thank You very much!

Pete Doyle

unread,
Aug 8, 2011, 6:07:54 PM8/8/11
to android-support-v4...@googlegroups.com
Replies inline below...

On Mon, Aug 8, 2011 at 2:13 AM, lomza_t <tonia....@gmail.com> wrote:
Another thing, is when I just created a project from the package
You've posted on GitHub, I've got some errors in ViewGroup, so I added
3 libraries to it, to make it work: android-13.jar, maps-13.jar and
android-support-v13.jar. Then I add this project to my project's Build
Path, run it and got the error, I've described above.

You actually don't need to add android-13.jar, maps-13.jar, or android-support-v13.jar.  

Use android-support-v4-googlemaps-r3.jar and set the Android Project Build Target to Google APIs level 6 or higher (I've only tested down to 11, but I think 6 should work).  Here's a screenshot of what that looks like in Eclipse:

When you have it right, default.properties (in the root of your project) will something like the following line (replace 11 with whatever API level you're using):
  target=Google Inc.:Google APIs:11

Its tricky-- you have to set the API level in _both_ the manifest _and_  in default.properties (which you can do from Eclipse.  See above screenshot & previous message).

I also tried to
create a simple project with MapView built in a Fragment, but it
failed... Can You, please, tell me the concept? I must have an
activity which extends FragmentActivity and in .xml layout I can simpy
built the  MapView inside a <fragment>, is this correct?
 
I'm working on building a sample based on the FragmentLayout sample mentioned here:

It's not 100% done yet, but you can see it on the dev-samples branch here:

Please read the comments carefully.  I've tried to explain the various hacks that are needed and why.  There's still some bugs, but I'll try to fix them in the next few days.

If you want to run it locally, clone the repo, switch to the dev-samples branch, then import the project to Eclipse:

    git clone g...@github.com:petedoyle/android-support-v4-googlemaps.git
    git checkout dev-samples
    
    in Eclipse:
    File > Import... > Existing Projects into Workspace > Select root directory: $WORKSPACE/android-support-v4-googlemaps/src/samples/FragmentLayoutMaps 

You'll have to edit src/samples/FragmentLayoutMaps/res/values/strings.xml.  Uncomment google_maps_api_key and put your API key, which you can get here if you don't already have one:

With all of that said, you'll see this really is a huge hack.  Depending on your needs, you might be able to get away with using a WebView pointing at Google Maps API v3.  That's what they do in the Google IO 2011 app here:

That said, for my app, WebView + Google Maps API v3 renders much too slowly, so I'm using this hack.


Thank You very much!

You're welcome :)
Pete
--
Pete Doyle

lomza_t

unread,
Aug 9, 2011, 5:32:26 AM8/9/11
to Android Compatibility Library for Google Maps - Support
Hi,

Oh, what a wonderful answer!
I want to THANK YOU for Your reply. It really works!
Though, there are few bugs (portrait configuration, weird behave...) ,
but I will try to resolve them by myself.
Thanks one more time! You did a great job!
Reply all
Reply to author
Forward
0 new messages