How to get Android project and std Java project to play nice?
I can now get our Android project to talk to our non-Android project. But there's still an issue:
I are trying to have an Android class call a non Android Hello World class.
I tried compiling our non-Android Hello World class in a separate Eclipse workspace. I then packaged it into a jar. I imported that jar into our Android Hello World class.
I then called one of the methods in the non-Android Hello World class.
When I ran the Android Hello World class as an Android application, the following runtime error occurred. Here are the Android debug logs:
08-11 09:07:56.764: ERROR/AndroidRuntime(333): FATAL EXCEPTION: main
08-11 09:07:56.764: ERROR/AndroidRuntime(333): java.lang.ExceptionInInitializerError
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at com.hello2.hello2.onCreate(hello2.java:27)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1047)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2627)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2679)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.app.ActivityThread.access$2300(ActivityThr ead.java:125)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:2033)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.os.Handler.dispatchMessage(Handler.java:99 )
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.os.Looper.loop(Looper.java:123)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at android.app.ActivityThread.main(ActivityThread.jav a:4627)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at java.lang.reflect.Method.invoke(Method.java:521)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:868)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:626)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at dalvik.system.NativeStart.main(Native Method)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): Caused by: java.lang.ExceptionInInitializerError
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.Logger.getLogger(Logger.java:118)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at helloArtifactJarTest.seconddirectory.TestJar.Hello PleasePleasePrint.<clinit>(HelloPleasePleasePrint. java:7)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): ... 14 more
08-11 09:07:56.764: ERROR/AndroidRuntime(333): Caused by: java.lang.VerifyError: org.apache.log4j.config.PropertySetter
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.PropertyConfigurator.parseAppende r(PropertyConfigurator.java:684)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.PropertyConfigurator.parseCategor y(PropertyConfigurator.java:647)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.PropertyConfigurator.configureRoo tCategory(PropertyConfigurator.java:544)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.PropertyConfigurator.doConfigure( PropertyConfigurator.java:440)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.PropertyConfigurator.doConfigure( PropertyConfigurator.java:476)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.a开发者_Go百科pache.log4j.helpers.OptionConverter.selectAnd Configure(OptionConverter.java:471)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): at org.apache.log4j.LogManager.<clinit>(LogManager.ja va:125)
08-11 09:07:56.764: ERROR/AndroidRuntime(333): ... 16 more
It seems that I can run HelloPleasePleasePrint as a Java application fine, with it properly using the log4j logger. But when we try calling a method in HelloPleasePleasePrint from the hello2 Android class, it complains about the log4j.
Any Help or references would be greatly appreciated.
To get rid of the log4j errors, you can try to use android-logging-log4j. See log4j support in android. It is important that the log4j system is not configured using a log4j.properties or log4j.xml file from the classpath.
精彩评论