I have a project which uses a WelcomeActivity which extends FragmentActivity. I use the support library, so android-support-v4.jar is in the libs folder. When I run this app, there are no problems.
However, I want to add ActionBarSherlock to the project. In the ABS project I use actionbarsherlock-plugin-maps-4.1.0.jar and android-support-v4-r6-googlemaps.jar in the libs folder. In my app project I add the ABS library, and when I try to run the app, this error occurs:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoStubImpl;
To solve this, I removed the android-support-v4.jar from my app's libs folder. When I now start my app, the app crashes with this logcat:
08-01 18:59:11.182: W/dalvikvm(13338): Unable to resolve superclass of Landroid/support/v4/app/FragmentActivity; (620)
08-01 18:59:11.182: W/dalvikvm(13338): Link of class 'Landroid/support/v4/app/FragmentActivity;' failed
08-01 18:59:11.182: W/dalvikvm(13338): Unable to resolve superclass of Lcom/myapp/welcome/WelcomeActivity; (109)
08-01 18:59:11.182: W/dalvikvm(13338): Link of class 'Lcom/myapp/welcome/WelcomeActivity;' failed
08-01 18:59:11.182: E/dalvikvm(13338): Could not find class 'com.myapp.welcome.WelcomeActivity', referenced from method com.myapp.MainDispatcherActivity.startWelcomeActivity
08-01 18:59:11.182: W/dalvikvm(13338): VFY: unable to resolve const-class 690 (Lcom/myapp/welcome/WelcomeActivity;) in Lcom/myapp/MainDispatcherActivity;
08-01 18:59:11.182: D/dalvikvm(13338): VFY: replacing opcode 0x1c at 0x0002
08-01 18:59:11.182: D/dalvikvm(13338): VFY: dead code 0x0004-000b in Lcom/myapp/MainDispatcherActivity;.startWelcomeActivity ()V
08-01 18:59:11.182: D/AndroidRuntime(13338): Shutting down VM
08-01 18:59:11.182: W/dalvikvm(13338): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-01 18:59:11.182: E/AndroidRuntime(13338): FATAL EXCEPTION: main
08-01 18:59:11.182: E/AndroidRuntime(13338): java.lang.NoClassDefFoundError: com.myapp.welcome.WelcomeActivity
08-01 18:59:11.182: E/AndroidRuntime(13338): at com.myapp.MainDispatcherActivity.startWelcomeActivity(MainDispatcherActivity.java:33)
08-01 18:59:11.182: E/AndroidRuntime(13338): at com.myapp.MainDispatcherActivity.startProperActivity(MainDispatcherActivity.java:26)
08-01 18:59:11.182: E/AndroidRuntime(13338): at com.myapp.MainDispatcherActivity.onCreate(MainDispatcherActivity.java:19)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.os.Looper.loop(Looper.java:130)
08-01 18:59:11.182: E/AndroidRuntime(13338): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 18:59:11.182: E/AndroidRuntime(13338): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 18:59:11.182: E/AndroidRuntime(13338): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 18:59:11.182: E/AndroidRuntime(13338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
08-01 18:59:11.182: E/AndroidRuntime(13338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
08-01 18:59:11.182: E/AndroidRuntime(13338): at dalvik.system.NativeStart.main(Native Method)
How can I fix this?
Edit
I have another project which uses the same ABS library, and runs fine. I have no idea what I've done differently, or which settings are wrong.
It seems this error occurred because I didn't have this line in the AndroidManifest.xml file, in the <application> tag:
<uses-library android:name="com.google.android.maps" />
Click here
I think it is the same problem at the Build Path-> Configure Build Path -> Order and Export, the "android-support-v4.jar" needs to be checked.
Hope it is useful to you.
Have you set the compiler compliance for the actionbarsherlock library project? Right click on the library project, go to properties. Under java compiler, make sure compliance is set to 1.6. I had a similar issue, and found the compliance set to 1.5.
I haven't run into it myself, but I think the doc for ActionBarSherlock says you need to extend SherlockFragmentActivity rather than FragmentActivity. It may not be the problem, but it's a problem.
Related
I have add into my project's libralies the andriod-support-v4.jar... but I am getting this error:
Could not find class 'android.app.Notification$Builder', referenced from method org.secure.sms.SmsReceiver.showNotification
Could not find class 'android.support.v4.app.NotificationCompat$Builder', referenced from method org.secure.sms.SmsReceiver.createNotification
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v4.app.NotificationCompat$Builder
at org.secure.sms.SmsReceiver.createNotification(SmsReceiver.java:108)
at org.secure.sms.SmsReceiver.onReceive(SmsReceiver.java:136)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)
at android.app.ActivityThread.access$2400(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Where is the problem??
Screenshot: http://i.stack.imgur.com/I95ke.jpg
be sure to have android-support-v4.jar inside your folder /libs
and add this to your class:
import android.support.v4.app.NotificationCompat;
i'm getting this message when i run my application i don't know why i'm getting it could any one help me. here is the logcat.
java.lang.VerifyError: com.kosh.me.Smaller
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
This happens when the build library classes conflict with those at run-time. Try performing a Clean of your project followed by a build.
I am trying to run my application, but whenever I make a call to a native function it gives me an error and the program crashes. I'm sure it has to do with how I am naming something either in Java or in C.
Here is my call to the functions in Java :
package my.commander;
public class RelayAPIModel {
public static class NativeCalls {
static {
System.loadLibrary( "RelayAPI");
}
public native static byte InitRelayJava();
public native static void FreeRelayJava();
}
Here are the functions in the .c file:
void Java_my_commander_RelayAPIModel_FreeRelayJava( JNIEnv * env, jobject this ) {
RelayAPI_DataValid = 0;
RelayAPI_SetBaud = 0;
RelayAPI_get = 0;
RelayAPI_put = 0;
RelayAPI_flush = 0;
RelayAPI_delay = 0;
RelayAPI_initilized = 0;
}
BYTE Java_my_commander_RelayAPIModel_InitRelayJava( JNIEnv *env, jobject obj ) {
...
...
}
Here they are in the .h file :
void Java_my_commander_RelayAPIModel_FreeRelayJava( JNIEnv * env, jobject obj );
BYTE Java_my_commander_RelayAPIModel_InitRelayJava( JNIEnv *env, jobject obj );
Here is my LogCat:
08-01 09:58:21.933: E/AndroidRuntime(17170): FATAL EXCEPTION: main
08-01 09:58:21.933: E/AndroidRuntime(17170): java.lang.UnsatisfiedLinkError: InitRelayJava
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava(Native Method)
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.os.Looper.loop(Looper.java:130)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 09:58:21.933: E/AndroidRuntime(17170): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 09:58:21.933: E/AndroidRuntime(17170): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 09:58:21.933: E/AndroidRuntime(17170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 09:58:21.933: E/AndroidRuntime(17170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 09:58:21.933: E/AndroidRuntime(17170): at dalvik.system.NativeStart.main(Native Method)
I would like to clarify now, that I have tried changing the C method names to Java_my_commander_RelayAPIModel_NativeCalls_FreeRelayJava and Java_my_commander_RelayAPIModel_NativeCalls_InitRelayJava. The application still failed to launch and this was the LogCat for that:
08-01 11:22:10.735: E/AndroidRuntime(17441): FATAL EXCEPTION: main
08-01 11:22:10.735: E/AndroidRuntime(17441): java.lang.UnsatisfiedLinkError: InitRelayJava
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava(Native Method)
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.os.Looper.loop(Looper.java:130)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 11:22:10.735: E/AndroidRuntime(17441): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 11:22:10.735: E/AndroidRuntime(17441): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 11:22:10.735: E/AndroidRuntime(17441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 11:22:10.735: E/AndroidRuntime(17441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 11:22:10.735: E/AndroidRuntime(17441): at dalvik.system.NativeStart.main(Native Method)
Now, I think that the error lies in the code above. If you all think there is nothing wrong with it, I'm going to add some more information down here just in case the problem lies elsewhere.
This application that I'm creating, uses the functions above to call a library that has been being used for a while. This library was previously used to call functions in a Palm Pilot program which utilize the Palm's bluetooth capabilities. Since Android devices have different bluetooth libraries/capabilities, I am adding code to the native library to call BACK to the java code, to access the Android device's bluetooth capabilities. I do not want to post all of the code pertaining to this here, but if someone feels that it needs to be posted I will.
The error message says it's at:
my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava (Native Method)
So make sure that:
the native method declaration is indeed inside the RelayAPIModel class, not insude the RelayAPIModel.NativeCalls nested class.
the package name on Java side is my.commander as opposed to my.eti.commander
EDIT: or you can fix that on the C side. If you want to create native methods in the nested class, the proper name for it would be:
Java_my_commander_RelayAPIModel_00024NativeCalls_InitRelayJava()
The 00024 is the code of the $ character, which is the nested class delimiter in Java internals. Also, the meaning of the of second parameter (jobject Obj) will be different - instead of this pointer/class pointer for RelayAPIModel, it will be the one for the RelayAPIModel.NativeCalls. You won't be able to use it to resolve/call methods in the RelayAPIModel.
You can use javah to generate a .h file with the correctly named native files:
javah -jni -classpath bin/classes com.example.app.MyClass
Two days ago, when my android project in eclipse still worked, I added "android SDK 4.0.3" to my SDKs (in addition to android SDK 2.1).
From that moment on, I have a trouble with slf4j-android library; here's the exception:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1479)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
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:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at it.cefriel.swa.urbanopoly.client.game.UrbanopolyActivity.<clinit>(UrbanopolyActivity.java:11)
The JAR I use is slf4j-android-1.5.8.jar. The build path seems correctly setted. I also tried to create another project using slf4j and I got the same error..
Any Ideas?
Thanks in advance
Try adding the slf4j-api-1.5.8.jar or latest version as well with the current slf4j-android-1.5.8.jar
I included a jar file in my Android project as explained in How can I use external JARs in an Android project?. With both methods described by MannyNS and Vinayak B. in this post I get the error "Could not find class 'test.libraryCalc.Calc" which is the class provided by the library. The following code illustrates the problem:
Example class provided via library: Calc.java
package test.libraryCalc;
public class Calc {
public int add(int a, int b){
return a + b;
}
}
LibraryTestActivity.java
package test.library;
import test.libraryCalc.Calc;
import android.app.Activity;
import android.os.Bundle;
public class LibraryTestActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Calc calc = new Calc();
int c = calc.add(3, 4);
}
}
I exported the jar file containing Calc.java to LibraryTest\libs\calc.jar
and added a reference to it using the "Add JARs..." button in the Java Build Path of LibraryTest
The library shows up in the Referenced libraries in LibraryTest
LibraryTest has no build problems but when running it on the emulator the following is shown in LogCat:
12-27 14:01:33.965: E/dalvikvm(747): Could not find class 'test.libraryCalc.Calc', referenced from method test.library.LibraryTestActivity.onCreate
12-27 14:01:33.965: W/dalvikvm(747): VFY: unable to resolve new-instance 13 (Ltest/libraryCalc/Calc;) in Ltest/library/LibraryTestActivity;
12-27 14:01:33.995: D/dalvikvm(747): VFY: replacing opcode 0x22 at 0x0008
12-27 14:01:33.995: D/dalvikvm(747): VFY: dead code 0x000a-0013 in Ltest/library/LibraryTestActivity;.onCreate (Landroid/os/Bundle;)V
12-27 14:01:34.065: D/AndroidRuntime(747): Shutting down VM
12-27 14:01:34.065: W/dalvikvm(747): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-27 14:01:34.075: E/AndroidRuntime(747): FATAL EXCEPTION: main
12-27 14:01:34.075: E/AndroidRuntime(747): java.lang.NoClassDefFoundError: test.libraryCalc.Calc
12-27 14:01:34.075: E/AndroidRuntime(747): at test.library.LibraryTestActivity.onCreate(LibraryTestActivity.java:14)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.os.Looper.loop(Looper.java:123)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 14:01:34.075: E/AndroidRuntime(747): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 14:01:34.075: E/AndroidRuntime(747): at java.lang.reflect.Method.invoke(Method.java:521)
12-27 14:01:34.075: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-27 14:01:34.075: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-27 14:01:34.075: E/AndroidRuntime(747): at dalvik.system.NativeStart.main(Native Method)
12-27 14:06:34.170: I/Process(747): Sending signal. PID: 747 SIG: 9
What needs to be done to get this working? Thanks for all suggestions.
I think that the problem is that you try to add jar that contains Android code. You cannot do this. To include Android code you should create Android library. Simply create an Android project and in the project-properties Android section set that this is library project. After that you'll be able to add this library to your projects. For more about Android libraries you can read here.
Update: I've tried your code now. It works in my case. The only difference that I've made is during export of Jar I've checked Export Java source files and resources. Hope this will help you. Try it!