Eclipse and Android SL GridLayout not working together - "android.support.v7.widget.GridLayout could not be instantiated"
Asked Answered
S

2

2

I'm new to Android development, so it's possible this is a simple question. Apologies if it is - I spent quite some time searching but couldn't find anything that worked.

I'm trying to use a GridLayout in my project, but ideally with the Android Support Library so I can target lower versions of the API. When I drag a GridLayout into the graphical layout designer, a message pops up asking explaining I need a compatibility library for API versions older than 14, and asks if I want to install this library. I hit "Install" and let Eclipse do its thing, but an error shows up in the Eclipse graphical layout designer: The following classes could not be instantiated: - android.support.v7.widget.GridLayout See the Error Log ( Window > Show View) for more details. (Screenshot)

From the error log, android.support.v7.widget.GridLayout failed to instantiate. Here's the stack trace

My search for this error turned up this SO thread, which seemed promising; I checked my Java, Eclipse and ADT versions but all seem to be reasonably up-to-date (Java 7 update 17, Eclipse Juno release, ADT 21.1). With the update checks out of the way, I looked at how that SO user had his project set up: a library project for the gridlayout, a project reference to this library in the main project, and the gridlayout jar copied into the main project's libs folder. Following the Eclipse "install compatibility library" message, a gridlayout library project had already been created for me, but the project reference had not been set up and the gridlayout jar hadn't been copied. I did both these things but still the GridLayout fails to instantiate.

I continued searching and found another SO thread. Despite that thread not using Eclipse, I attempted to translate the answer into the Eclipse equivalent, which was roughly the same as given by the thread above. (Copy the gridlayout jar to the project's libs folder, create a library project from gridlayout, and add a project reference to that library project from within the main project.) I also verified that the gridlayout jar is on the main project's build path. (Screenshot)

I also attempted to follow the instructions in the relevant Styling Android blogpost, but that's even worse: when I try to drag a GridLayout into my project, it throws two errors, a RelativeLayoutRule.onDropped() failed: java.lang.NullPointerException with this stack trace and an Initializing project state with this stack trace. Based on the IOException mentioned in the "Initializing project state" stack trace, I speculated the problem might be my install location for the Android SDK: %APPDATA%\Local\Android. I finally tried uninstalling the SDK and reinstalling it to %PROGRAMFILES%\Android but without any luck.

I'm not really sure where to go from here. If anyone could give me a pointer in the right direction, I'd really appreciate it!

Sheelagh answered 4/4, 2013 at 16:9 Comment(2)
refer second answer...#12376651Humiliate
Are you suggesting I roll my own GridLayout equivalent? That's definitely an interesting idea, but I'm not sure I know enough about Droid coding yet to do it correctly.Sheelagh
S
2

Try: File->Import->Existing Android code into workspace Specify android-sdk-[platform]/extras/android/support/v7/gridlayout

You need to import the GridLayout project as an Android library project for it to work.

Stauder answered 5/4, 2013 at 5:42 Comment(2)
I did try that several times, but with no luck. Probably should've mentioned that in my OP.Sheelagh
Finally got it working - it was a combination of factors, I think. I ended up reinstalling the Android SDK to a path without spaces, downgraded my JDK from version 7 to version 6, and directly imported the GridLayout project like you suggested. Giving you the answer because I wasn't sure whether I needed to use the support library's .jar or the project before your post. Thanks!Sheelagh
H
1

i meant clear your build path...

Try this:

right click your project->properties->java build path->order and export where tick mark all option

Humiliate answered 4/4, 2013 at 18:33 Comment(2)
I just created a new project, dragged a GridLayout into it, and let Eclipse install the compatibility library. I checked that the auto-generated gridlayout project was marked as a library - all good. My project references the gridlayout project in Properties->Android - all good. gridlayout_v7.jar is on the build path in Properties->Java Build Path ->Libraries->Android Dependencies - all good. In Properties->Java Build Path->Order and Export, everything is checked - all good. But for some reason I'm still getting the "could not be instantiated" error. Any other ideas?Sheelagh
then try another idea in link below #12376651Humiliate

© 2022 - 2024 — McMap. All rights reserved.