I've been building a custom Java library, and after importing it to my Android project, it results in a java.lang.NoClassDefFoundError
when I try to use it.
My library used to be part of my project, but I decided to "split it", and create a Java library instead. It imports a few libraries needed to work (org.json...), and has two packages.
To include it into my Android project, I just copy/pasted my library to the libs
folder of my Android project, and Eclipse detect it, and doesn't show me any error in my code, and the library seems to be added to the "Android Dependencies" folder. But, when I run the project, I have a java.lang.NoClassDefFoundError Exception in the first line my library is required.
If one of you could help me to figure out this issue, I'd be thankful. I can't even see what I've been doing wrong...
Edit: You can find the jar I'm using right here: https://docs.google.com/file/d/0B1rK0R07j--QZmJFMUpLVEdMNnc/edit?usp=sharing and the sources https://github.com/MagicMicky/HabitRPGJavaAPI
Note: The library seems to work with a normal Java project.
My LOGCAT below:
05-21 00:27:59.349: E/AndroidRuntime(11797): FATAL EXCEPTION: main
05-21 00:27:59.349: E/AndroidRuntime(11797): java.lang.NoClassDefFoundError: com.magicmicky.habitrpgmobileapp.MainActivity$1
05-21 00:27:59.349: E/AndroidRuntime(11797): at com.magicmicky.habitrpgmobileapp.MainActivity.<init>(MainActivity.java:44)
05-21 00:27:59.349: E/AndroidRuntime(11797): at java.lang.Class.newInstanceImpl(Native Method)
05-21 00:27:59.349: E/AndroidRuntime(11797): at java.lang.Class.newInstance(Class.java:1319)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.os.Looper.loop(Looper.java:137)
05-21 00:27:59.349: E/AndroidRuntime(11797): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-21 00:27:59.349: E/AndroidRuntime(11797): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 00:27:59.349: E/AndroidRuntime(11797): at java.lang.reflect.Method.invoke(Method.java:511)
05-21 00:27:59.349: E/AndroidRuntime(11797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-21 00:27:59.349: E/AndroidRuntime(11797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-21 00:27:59.349: E/AndroidRuntime(11797): at dalvik.system.NativeStart.main(Native Method)
with MainActivity.java:44 being the first line I use my library...
Edit2: And here is the firsts line of my Android Project:
package com.magicmicky.habitrpgmobileapp;
import java.util.ArrayList;
import java.util.List;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.magicmicky.habitrpgmobileapp.habits.HabitItem;
import com.magicmicky.habitrpgmobileapp.habits.User;
import com.magicmicky.habitrpgmobileapp.onlineapi.GetUser;
import com.magicmicky.habitrpgmobileapp.onlineapi.HostConfig;
import com.magicmicky.habitrpgmobileapp.onlineapi.OnHabitsAPIResult;
import com.magicmicky.habitrpgmobileapp.onlineapi.WebServiceInteraction.Answer;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends SherlockFragmentActivity {
MyPagerAdapter fgsAdapter;
private TextView username_TV;
/* Other decarations...*/
private User user;//Note that this line is from my library, but doesn't throw an exception
OnHabitsAPIResult callback = new OnHabitsAPIResult() { // And this is line 44...
Handler mainHandler;
private int nbRequests=0;
@Override
public void onUserReceived(final User us) {
mainHandler = new Handler(getMainLooper());
Runnable myRunnable = new Runnable(){
public void run() {
user=us;
notifyDataChanged();
afterResults();
}
};
mainHandler.post(myRunnable);
}
};
/* And code continues...*/
Note that this code works well if I'm copying/pasting the library files into the project (instead of importing the jar library)...