I want to use slf4j with logback in my Android application (IDE Eclipse).
I have already added the jars file (slf4j-api-1.7.1 logback-android-1.0.7-1.jar) to build path in Eclipse.
I try to launch my app in Adv with the following simple main activity
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public class MainActivity extends Activity{
private static final Logger logger =
LoggerFactory.getLogger(MainActivity.class);
private void onnCreate(Bundle svedInstanceState){
super.onCreate(savedInstanceState)
logger.debug("MainActivity created");
}
}
and i get the following error captured by logcat
10-02 16:03:46.911: I/dalvikvm(619): Could not find method org.slf4j.LoggerFactory.getLogger, referenced from method com.mbm.activity.MainActivity.<clinit>
10-02 16:03:46.911: W/dalvikvm(619): VFY: unable to resolve static method 3250: Lorg/slf4j/LoggerFactory;.getLogger (Ljava/lang/Class;)Lorg/slf4j/Logger;
10-02 16:03:46.941: I/dalvikvm(619): Could not find method org.slf4j.Logger.debug, referenced from method com.mbm.activity.MainActivity.onToggleClicked
10-02 16:03:46.941: W/dalvikvm(619): VFY: unable to resolve interface method 3248: Lorg/slf4j/Logger;.debug (Ljava/lang/String;)V
10-02 16:03:46.941: I/dalvikvm(619): Could not find method org.slf4j.Logger.info, referenced from method com.mbm.activity.MainActivity.onToggleClicked
10-02 16:03:46.941: W/dalvikvm(619): VFY: unable to resolve interface method 3249: Lorg/slf4j/Logger;.info (Ljava/lang/String;)V
10-02 16:03:46.951: W/dalvikvm(619): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/mbm/activity/MainActivity;
10-02 16:03:46.951: W/dalvikvm(619): Class init failed in newInstance call (Lcom/mbm/activity/MainActivity;)
10-02 16:03:46.951: W/dalvikvm(619): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
10-02 16:03:46.961: E/AndroidRuntime(619): FATAL EXCEPTION: main
10-02 16:03:46.961: E/AndroidRuntime(619): java.lang.ExceptionInInitializerError
10-02 16:03:46.961: E/AndroidRuntime(619): at java.lang.Class.newInstanceImpl(Native Method)
10-02 16:03:46.961: E/AndroidRuntime(619): at java.lang.Class.newInstance(Class.java:1319)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.os.Handler.dispatchMessage(Handler.java:99)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.os.Looper.loop(Looper.java:137)
10-02 16:03:46.961: E/AndroidRuntime(619): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-02 16:03:46.961: E/AndroidRuntime(619): at java.lang.reflect.Method.invokeNative(Native Method)
10-02 16:03:46.961: E/AndroidRuntime(619): at java.lang.reflect.Method.invoke(Method.java:511)
10-02 16:03:46.961: E/AndroidRuntime(619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-02 16:03:46.961: E/AndroidRuntime(619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-02 16:03:46.961: E/AndroidRuntime(619): at dalvik.system.NativeStart.main(Native Method)
10-02 16:03:46.961: E/AndroidRuntime(619): Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
10-02 16:03:46.961: E/AndroidRuntime(619): at com.mbm.activity.MainActivity.<clinit>(MainActivity.java:41)
10-02 16:03:46.961: E/AndroidRuntime(619): ... 15 more
Please help me.
i solved alone the issue with the following steps:
1) put the 2 jar files in a new folder in your project.
2) add jars to build path
3) in Java Build Path prefernce enter in the “Order and Export” tab and select the two jars, then press ok.
4) Project –> Clean!!
After these steps the app runs fine without errors!!