Pergunta

I'm currently developing an Android Application which uses RESTful webservices to Communicate with the Service which is a Maven Project. We're using a Singleton Pattern to store the ResponseBeans we get from our Maven Project. But but as soon as the ResponseBean is beeing accessed at the SingletonClass I get a NoClassDefFoundError even though I've added the Maven project to the Java Build Path. I've been trying to fix this problem the whole day but I can't find a solution.

This is the Error Message I get:

04-28 21:17:27.889: E/AndroidRuntime(1584): FATAL EXCEPTION: main
04-28 21:17:27.889: E/AndroidRuntime(1584): java.lang.NoClassDefFoundError: ch.uzh.ifi.seal.soprafs14.common.beans.user.UserResponseBean
04-28 21:17:27.889: E/AndroidRuntime(1584):     at ch.uzh.ifi.seal.soprafs14.group_09_android.model.GameDataSingleton.<init>(GameDataSingleton.java:32)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at ch.uzh.ifi.seal.soprafs14.group_09_android.model.GameDataSingleton.getInstance(GameDataSingleton.java:45)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at ch.uzh.ifi.seal.soprafs14.group_09_android.gui.activities.MenuActivity.onCreate(MenuActivity.java:55)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.Activity.performCreate(Activity.java:5104)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.os.Looper.loop(Looper.java:137)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at java.lang.reflect.Method.invoke(Method.java:511)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 21:17:27.889: E/AndroidRuntime(1584):     at dalvik.system.NativeStart.main(Native Method)
04-28 21:17:31.293: I/Process(1584): Sending signal. PID: 1584 SIG: 9

this is the Class where I get the exception

    package ch.uzh.ifi.seal...;

import ch.uzh.ifi.seal.soprafs14.common.beans.lobby.LobbyResponseBean;
import ch.uzh.ifi.seal.soprafs14.common.beans.user.UserResponseBean;

/**
 * This singleton class contains all game data on the client and allows to
 * access this data from all activities in the application.
 * 
 */
public class GameDataSingleton {
    private static GameDataSingleton instance = null;

    private String username;

    /**
     * Contains user data like ID, username and token.
     */
    private UserResponseBean user;

    /**
     * Contains lobby data like lobbyID and a list of all players.
     */
    private LobbyResponseBean lobby;

    /**
     * Private Constructor -> Singleton pattern
     */
    private GameDataSingleton() {
        user = new UserResponseBean();  // I get the Error at this line
        lobby = new LobbyResponseBean();
        username = "";
    }

    /**
     * Returns instance of GameDataSingleton or if it does not yet exist,
     * creates a new instance.
     * 
     * @return GameDataSingleton instance
     */
    public static GameDataSingleton getInstance() {
        if (instance == null) {
            instance = new GameDataSingleton();
        }
        return instance;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public UserResponseBean getUser() {
        return user;
    }

    public void setUser(UserResponseBean user) {
        this.user = user;
    }

    public LobbyResponseBean getLobby() {
        return lobby;
    }

    public void setLobby(LobbyResponseBean lobby) {
        this.lobby = lobby;
    }
}

Thanks in advance!

Foi útil?

Solução

You get this exception because DVM can't find the the UserResponseBean in your apk.

Try to re-check your maven dependency(I'm assuming you are using maven) and make sure it is correct.

if you are using a .jar library try to move it to libs folder.

Let me know what happens.

Outras dicas

Try Properties->Java Build Path->Libraries->Add Library ->User Library!!!!!! I think that it's solution for you.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top