imported library generates errors - android

I have the Jama library imported but I'm still getting the following errors:
08-21 15:29:10.153: E/AndroidRuntime(655): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-21 15:29:10.153: E/AndroidRuntime(655): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-21 15:29:10.153: E/AndroidRuntime(655): at dalvik.system.NativeStart.main(Native
Method)
08-21 15:29:54.233: E/dalvikvm(664): Could not find class 'Jama.Matrix', referenced
from method amr.NAVKA_Projekt.MPTest.RotationMatrix.calcDirectionVector
Any idea how to fix this?

Is the library being exported along with the rest of your code? Assuming you're using Eclipse, If you right click on the project -> Properties -> Java build path -> Go to the "Order and Export" tab and make sure the Jama library is checked.
If it's not, the library isn't included with the rest of the project when it is built, which is usually what leads to things like "Class not found" errors.

Related

Android Studio - add and reference the Google Play services library without Gradle [duplicate]

I'd like to import (and use) the Google Play Services library into an existing Android project, but I am struggling with what must be a dependency problem.
All documentation written by google is based upon Eclipse. We use IntelliJ IDEA.
Things I know:
I know how to import Modules, Libraries, add Dependencies, etc. in IntelliJ.
I also know that according to the getting started guide at Google, you have to add the google-play-services-lib into (Eclipse) as a project (by importing existing code into the workspace), and that you can do this in IntelliJ by adding a new module from existing code. It's the same procedure, different name.
I also understand what the Order and Export tab does in Eclipse (IntelliJ does it too).
Things I've done:
I copied (for safety) the google-play-services_lib folder from the Android SDK to my project root. So I have /myprj and /google-play-services_lib at the same level (I also have /facebooksdk and /actionbarsherlock at the same level) and proceeded to "Import Module" (from existing source). Then clicked next next next… (it worked, it was recognized).
The project structure looks like this (name intentionally blurred):
This correctly added a module (as you can see in the above screenshot). Now I need to add the dependency so my main project knows about this. I go to my modules and in the list, select my main module and then dependencies tab. I can see a few libraries (Joda time, android-query, gson, etc.) and two modules: FacebookSDK and actionbarsherlock. So far so good. And this is when things get weird.
Dependencies I've tried to add.
NOTE: In most cases I tried checking and unchecking the export checkbox and also tried adding this to the sherlockbar module at the same time, just for testing. I know these are a lot of combinations, but oh well.
1) Add a Jar or directory (knowing this was wrong, I tried). and pointed to the .jar that is inside the google play module /libs, named: google-play-services.jar.
2) Add a Library (and then adding it to the project(s))
3) Add the Module Dependency, (while having my main project selected). This shows you a pop-up like this:
PROBLEM
Even tho I can reference a PlusClient and I get the right imports, when I try to add a SignInButton in my layout xml, I get an error.
There's no point in pasting the whole XML Layout because it doesn't have anything strange, it's just a RelativeLayout with a few textviews. I added the g+ button like this:
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logo_login"
android:layout_marginBottom="30dip" />
Just like Google says.
The first sign that something may be out of order is the fact that IntelliJ warnings you that the element is "not valid here", but I assume that's a limitation of the visual designer rather than a real problem.
However, when I run the project, I get this:
07-30 17:50:44.854: ERROR/ActivityThread(22324): Failed to inflate
android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
Here is the line that gets my attention:
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
The next exception below is:
07-30 17:50:44.870: ERROR/AndroidRuntime(22324): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.ui.activities.LoginSignupActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
If I remove the code from the Layout, it works.
My idea is that this has to do with the way Android handles the R(esources) and therefore it may not be finding the resource for the button.
Has anybody managed to use: Intellij Idea (12+) with ActionbarSherlock and Google+ Library?
If so, how? :)
For historical reasons, I'm going to reproduce what I did, taken from here. Many thanks to #Hesam who found it. I will vote to close the whole question.
Note: the shortcuts are for OS X and Intellij 12 and 13.
Make sure you have the latest SDK/ADT Tools and the play services. They change every now and then and are usually not backwards compatible.
UPDATE I had to do this again, so this is the polished version of what I did.
You need to have a copy (as opposed to using it directly from the SDK folder), because if Google updates it, things are going to break when you update your SDK, it's safer to keep a copy (albeit more tedious because you will have to manually update when a new version comes out). I found out that it's better to decide when to update than to be surprised with cryptic compilation errors.
With that in mind, copy the library alongside your project. You should have a folder structure that looks like:
/something/yourmainmodule/
/something/any_other_module/
/something/modules.xml
/something/README.md (if you use github) :)
The library is located in
"ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib
ANDROID-SDK is wherever you stored the SDK when you downloaded it. Google changes this every now and then, so just find it, it will be there.
Copy that entire folder so your project now looks like this:
/something/yourmainmodule/
/something/any_other_module/
/something/google-play-services_lib/ <-- THIS IS THE NEW ONE
/something/modules.xml
/something/README.md
Good, now let's import it to IntelliJ-IDEA the right way:
1) Select your project/main module from project panel (⌘ 1) and hit ⌘ ↓ in order to open project structure window or just do File -> Project Structure.
2) Select Modules from left panel, then hit + button (or ⌘ N) then select "import module" and navigate to the google-play-services_lib that you just copied next to your project's module folder. (/something/).
The wizard will ask a series of questions, just hit next, defaults are fine, but read what's going on, understand what's happening, this is a core concept in Java, Android and Intellij. Experiment if you don't know what each dialog is saying (or why some may be empty).
After you're done, the google play Project will be added to Modules alongside with your project.
Don't close this window (or open it again if you did).
3) Still in the modules, select your project/module, then select "Dependencies" from right panel (it's a tab) and finally Click + button at the bottom (or ⌘ N which will work if you have the focus in this tab), then from the popup chose "3 Module dependencies..." and select "google-play-services_lib", which you added in the previous step. It should be there. If it's not, you didn't add the module in step 2.
4) Finally, Click + button again (or ⌘ N) but this time select "1 jars or directories...", navigate to the "/libs" folder of the above path and select "google-play-services.jar".
5) Click ok and close project structure window.
If you did this, your main module should have a dependency that looks like this:
Also make sure that in the Project Structure window, FACETS Tab, the Google Play Services has the "Library Module" checked. It is a library module.
Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.
Credit: this text comes from this StackOverflow answer

Google+ SignInButton class cannot be instantiated in Eclipse [duplicate]

I'd like to import (and use) the Google Play Services library into an existing Android project, but I am struggling with what must be a dependency problem.
All documentation written by google is based upon Eclipse. We use IntelliJ IDEA.
Things I know:
I know how to import Modules, Libraries, add Dependencies, etc. in IntelliJ.
I also know that according to the getting started guide at Google, you have to add the google-play-services-lib into (Eclipse) as a project (by importing existing code into the workspace), and that you can do this in IntelliJ by adding a new module from existing code. It's the same procedure, different name.
I also understand what the Order and Export tab does in Eclipse (IntelliJ does it too).
Things I've done:
I copied (for safety) the google-play-services_lib folder from the Android SDK to my project root. So I have /myprj and /google-play-services_lib at the same level (I also have /facebooksdk and /actionbarsherlock at the same level) and proceeded to "Import Module" (from existing source). Then clicked next next next… (it worked, it was recognized).
The project structure looks like this (name intentionally blurred):
This correctly added a module (as you can see in the above screenshot). Now I need to add the dependency so my main project knows about this. I go to my modules and in the list, select my main module and then dependencies tab. I can see a few libraries (Joda time, android-query, gson, etc.) and two modules: FacebookSDK and actionbarsherlock. So far so good. And this is when things get weird.
Dependencies I've tried to add.
NOTE: In most cases I tried checking and unchecking the export checkbox and also tried adding this to the sherlockbar module at the same time, just for testing. I know these are a lot of combinations, but oh well.
1) Add a Jar or directory (knowing this was wrong, I tried). and pointed to the .jar that is inside the google play module /libs, named: google-play-services.jar.
2) Add a Library (and then adding it to the project(s))
3) Add the Module Dependency, (while having my main project selected). This shows you a pop-up like this:
PROBLEM
Even tho I can reference a PlusClient and I get the right imports, when I try to add a SignInButton in my layout xml, I get an error.
There's no point in pasting the whole XML Layout because it doesn't have anything strange, it's just a RelativeLayout with a few textviews. I added the g+ button like this:
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logo_login"
android:layout_marginBottom="30dip" />
Just like Google says.
The first sign that something may be out of order is the fact that IntelliJ warnings you that the element is "not valid here", but I assume that's a limitation of the visual designer rather than a real problem.
However, when I run the project, I get this:
07-30 17:50:44.854: ERROR/ActivityThread(22324): Failed to inflate
android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
Here is the line that gets my attention:
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
The next exception below is:
07-30 17:50:44.870: ERROR/AndroidRuntime(22324): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.ui.activities.LoginSignupActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.android.gms.common.SignInButton
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at com.myapp.ui.activities.LoginSignupActivity.onCreate(LoginSignupActivity.java:64)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 24 more
Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable
at com.google.android.gms.internal.aa.b(Unknown Source)
at com.google.android.gms.internal.aa.a(Unknown Source)
at com.google.android.gms.common.SignInButton.c(Unknown Source)
at com.google.android.gms.common.SignInButton.d(Unknown Source)
at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
at com.google.android.gms.common.SignInButton.<init>(Unknown Source)
... 27 more
If I remove the code from the Layout, it works.
My idea is that this has to do with the way Android handles the R(esources) and therefore it may not be finding the resource for the button.
Has anybody managed to use: Intellij Idea (12+) with ActionbarSherlock and Google+ Library?
If so, how? :)
For historical reasons, I'm going to reproduce what I did, taken from here. Many thanks to #Hesam who found it. I will vote to close the whole question.
Note: the shortcuts are for OS X and Intellij 12 and 13.
Make sure you have the latest SDK/ADT Tools and the play services. They change every now and then and are usually not backwards compatible.
UPDATE I had to do this again, so this is the polished version of what I did.
You need to have a copy (as opposed to using it directly from the SDK folder), because if Google updates it, things are going to break when you update your SDK, it's safer to keep a copy (albeit more tedious because you will have to manually update when a new version comes out). I found out that it's better to decide when to update than to be surprised with cryptic compilation errors.
With that in mind, copy the library alongside your project. You should have a folder structure that looks like:
/something/yourmainmodule/
/something/any_other_module/
/something/modules.xml
/something/README.md (if you use github) :)
The library is located in
"ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib
ANDROID-SDK is wherever you stored the SDK when you downloaded it. Google changes this every now and then, so just find it, it will be there.
Copy that entire folder so your project now looks like this:
/something/yourmainmodule/
/something/any_other_module/
/something/google-play-services_lib/ <-- THIS IS THE NEW ONE
/something/modules.xml
/something/README.md
Good, now let's import it to IntelliJ-IDEA the right way:
1) Select your project/main module from project panel (⌘ 1) and hit ⌘ ↓ in order to open project structure window or just do File -> Project Structure.
2) Select Modules from left panel, then hit + button (or ⌘ N) then select "import module" and navigate to the google-play-services_lib that you just copied next to your project's module folder. (/something/).
The wizard will ask a series of questions, just hit next, defaults are fine, but read what's going on, understand what's happening, this is a core concept in Java, Android and Intellij. Experiment if you don't know what each dialog is saying (or why some may be empty).
After you're done, the google play Project will be added to Modules alongside with your project.
Don't close this window (or open it again if you did).
3) Still in the modules, select your project/module, then select "Dependencies" from right panel (it's a tab) and finally Click + button at the bottom (or ⌘ N which will work if you have the focus in this tab), then from the popup chose "3 Module dependencies..." and select "google-play-services_lib", which you added in the previous step. It should be there. If it's not, you didn't add the module in step 2.
4) Finally, Click + button again (or ⌘ N) but this time select "1 jars or directories...", navigate to the "/libs" folder of the above path and select "google-play-services.jar".
5) Click ok and close project structure window.
If you did this, your main module should have a dependency that looks like this:
Also make sure that in the Project Structure window, FACETS Tab, the Google Play Services has the "Library Module" checked. It is a library module.
Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.
Credit: this text comes from this StackOverflow answer

ClassNotFoundException when downloaded from Google Play

I've got a problem involving ClassNotFoundException. When i "Run as android application" from eclipse it works fine, but when i download it from Google Play (same source code but "Exported as signed app") it crashes with the following stacktrace:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.larphoid.aeboing/com.larphoid.aeboing.BoingBoing}: java.lang.ClassNotFoundException: com.larphoid.aeboing.BoingBoing in loader dalvik.system.PathClassLoader[/data/app/com.larphoid.aeboing-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2703)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.larphoid.aeboing.BoingBoing in loader dalvik.system.PathClassLoader[/data/app/com.larphoid.aeboing-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1033)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
... 11 more
I've never had this problem before, and i'm not experienced yet in "reading" Stacktraces, so i'm pretty much puzzled at this. If anyone has some pointers or solution i'd appreciate it.
Thanks.
Gonna copy this from another question as I had the exact same problem before, and this is how I fixed it:
If you're running adt rev 22, you might not be exporting your libraries. I don't know why
Google did this exactly, but in the newest revolution you have to
check to make sure you're exporting your libraries yourself.
Right click your project, click Properties, and check Order & Export
under Java Build Path. It should look like this if you want to export
everything:
Afterwards, rebuild the application and export it again. It should be working now. To test, simply install the .apk to your phone manually before putting it on the store to make sure it works.
ClassNotFoundException indicates that something is missing on the classpath. Maybe you are missing a library in the classpath.
As the name suggests classNotFoundException in Java is a subclass of java.lang.Exception and Comes when Java Virtual Machine tries to load a particular class and doesn't found the requested class in classpath.
Maybe you change your package name while signing your apk.
Check your package and class name

Export android application occasionally packages the classes incorrectly

From Eclipse I righ cick the project, export the Android application and sign with a self generated keystore.
After export, occasionally I observe the APK file size is lesser than what I get normally.
When the APK file size is incorrect I encounter CNF exception for my application class i.e. DataSystem.
I extracted both correct & incorrect APKs.
With the help of dex2jar utility I converted the classes.dex to classes_dex2jar.jar and opened in java decompiler (jdgui).
I observe parent is clubbed with one of the child package and hence the other child classes of the parent does not exists.
Due to an incorrect packaging I face ClassNotFoundException on the launch of application.
java.lang.RuntimeException: Unable to instantiate application
com.tsf.esharp.DataSystem: java.lang.ClassNotFoundException:
com.tsf.esharp.DataSystem at
android.app.LoadedApk.makeApplication(LoadedApk.java:482) at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:3952)
at android.app.ActivityThread.access$1300(ActivityThread.java:128) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:137) at
android.app.ActivityThread.main(ActivityThread.java:4514) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.ClassNotFoundException: com.tsf.esharp.DataSystem at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501) at
java.lang.ClassLoader.loadClass(ClassLoader.java:461) at
android.app.Instrumentation.newApplication(Instrumentation.java:946)
at android.app.LoadedApk.makeApplication(LoadedApk.java:477) ... 11
more Force finishing activity
com.tsf.esharp.ui.activity/.LauncherActivity
As a precautionary measure, at the time of build I always observe the size of the APK if it is not normal I re-build it. But as my application is in development phase, the components are added/removed quite frequently and hence I do not have a fixed standard size to compare against, so to use this precaution is not practically possible always.
Is this a bug with ADT plugin? Please note, I am using latest revision i.e. 21.1.
Any help would be really appreciated.

Google map API v2 is not working

I am trying to run sample code mention here : Google Maps Android API V2 Sample code
but i am getting error NoClassDefFound. Below is my logcat.
Can any one help me to solve it.
Any help is highly appricated
Thanks
12-04 18:04:18.854: E/AndroidRuntime(1801): java.lang.ExceptionInInitializerError
12-04 18:04:18.854: E/AndroidRuntime(1801): at java.lang.Class.newInstanceImpl(Native Method)
12-04 18:04:18.854: E/AndroidRuntime(1801): at java.lang.Class.newInstance(Class.java:1319)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.os.Looper.loop(Looper.java:137)
12-04 18:04:18.854: E/AndroidRuntime(1801): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-04 18:04:18.854: E/AndroidRuntime(1801): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 18:04:18.854: E/AndroidRuntime(1801): at java.lang.reflect.Method.invoke(Method.java:511)
12-04 18:04:18.854: E/AndroidRuntime(1801): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-04 18:04:18.854: E/AndroidRuntime(1801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-04 18:04:18.854: E/AndroidRuntime(1801): at dalvik.system.NativeStart.main(Native Method)
12-04 18:04:18.854: E/AndroidRuntime(1801): Caused by: java.lang.NoClassDefFoundError: com.example.mapdemo.BasicMapActivity
12-04 18:04:18.854: E/AndroidRuntime(1801): at com.example.mapdemo.MainActivity.<clinit>(MainActivity.java:98)
12-04 18:04:18.854: E/AndroidRuntime(1801): ... 15 more
I had the same problem and got resolved by doing the following,
Remove the android-support-v4.jar that you added manually
Right click on the project and select Android Tools -> Add Support Library ...
After this everything worked for me.
This worked for me.
Once you have imported the Android-Support-V4.jar and the Google_Play_Services_lib.jar, go to:
Project Properties > Java Build Path > Order and Export.
Then ensure you the check boxes beside Android-Support-V4.jar and the Google_Play_Services_lib.jar are selected.
Click ok, then run. All should be well.
Following up on NewUserSOF's answer (and I am new to this):
I implemented Jairo's answer and the Google Maps V2 "MainActivity" ran and displayed the list of options.
But now when I click on any of them, my Emulator says I need to Update Google Play services. When I hit the "Update" button, the app crashes.
From LogCat:
12-19 16:02:44.902: W/GooglePlayServicesUtil(2431): Google Play services out of date. Requires 2012100 but found 1015
12-19 16:02:51.136: E/AndroidRuntime(2431): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://play.google.com/store/apps/details?id=com.google.android.gms flg=0x80000 pkg=com.android.vending }
Is there a way to Update the Google Play Services on the Emulator. (Emulator is Nexus S running Google API's 17).
Multiple reference of android-support-v4.jar
This is worked for me.
If your project and goolge play services library project both contain android-support-v4.jar then it will conflict.
Remove android-support-v4.jar from any one project.
Sounds like you are missing something important ;) Did you do these steps?
Select Project > Properties, select Java Build Path, and navigate to Libraries.
Select Add External Jars, include the following jar files, and click OK:
/extras/android/compatibility/v4/android-support-v4.jar
Add your own Google Maps Android API key.
Is the Google Play Services library project referenced as a library project from your Sampleproject?
Edit: Jairo's answer worked for me.
Edit2: It runs but no map shown. I have the API key in place. It's a new one just got it. Used package name com.example.mapdemo.
Edit3: Refreshed API key (they dont last long). Still no map shown.
Edit4: Had wrong SHA1 from using wrong keystore. When I searched for it, search did not find it in .android folder (ubuntu not searching hidden folder), instead showed me keystores I got from downloading android source code.
I'm having the exact same error.
MainActivity starts, refers to BasicMapActivity which is in the same package.
BasicMapActivity extends FragmentActivity which is in the android-support-v4.jar.
On this page: https://developers.google.com/maps/documentation/android/intro
See Step 4: "Select Add External Jars, include the following jar files, and click OK:
/extras/android/compatibility/v4/android-support-v4.jar"
My path was to the jar was /support/ instead of /compatibility/ - I don't have a /compatibility/ folder.
Maybe that's a clue?
My android-support-v4.jar has a Modified date of Mon 19 Nov 2012 09:14:47 AM EST. Makes me wonder if I am missing the latest update. SDK Manager has been run and rerun.
1) Verify that the debug keystore eclipse is using to sign your app is actually the one you have extracted the SHA1 hash to generate the api key
Go to:
Window > Android > Build > "Default debug keystore" and copy the path to the keystore
Run
keytool -list -v -keystore YOUR_KEYSTORE_PATH -alias androiddebugkey
2) Verify that you have entered the package of your application after the SHA1 hash in the API console configuration
Android apps:
XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;com.yourapp.package
3) I experienced this error at the beginning of my tests and i remember that an error was logged on Logcat. Something like "Authentication error" or "API key error" something like that. Just pay attention to the logcat on the first run of the app to check that you are not having issues with the API key.
If you experience this error, you will have to kill/reinstall the app. Fixing the api key while the app is still running did not entirely solve the issue.
4) I had to add the support jar into the libs folder inside the example app. Linking it as an external jar in the eclipse buildpath didn't work for me.
Depending on how your source is set up, you may need to set the android-support-library to be exported (right click->properties->java build path->order and export)
Also, you need to be using SupportMapFragment rather than MapFragment for the support library.
Make sure you're also using getSupportFragmentManager rather than getFragmentManager.
For me the issue was Google Maps was not installed. I had wiped my tablet and forgot to reinstall it.

Categories

Resources