2012-03-13 27 views
0

我試圖從一個包中保存我的應用程序(保存在一個包中)。ClassNotFoundException當閱讀包裹

我的活動使用OpenGL,因此它創建這個表面視圖並在保存或恢復應用程序時調用這些函數。

class MySurfaceView extends GLSurfaceView { 
    /* Lots of other stuff */ 
    public void onRestoreInstanceState(Bundle inState) { 
     Log.d("Wormhole", "Restoring instance state"); 
     mRenderer.onRestoreInstanceState(inState); 
    } 

    public void onSaveInstanceState(Bundle outState) { 
     Log.d("Wormhole", "Saving instance state"); 
     mRenderer.onSaveInstanceState(outState); 
    } 
} 
在mRenderer

public void onRestoreInstanceState(Bundle inState){ 
    mFlowManager = inState.getParcelable("flowmanager"); 
} 

public void onSaveInstanceState (Bundle outState){ 
    outState.putParcelable("flowmanager", mFlowManager); 
} 

在mFlowManager

public class FlowManager implements Touchable, Parcelable { 
private enum State { 
    SPLASH, MENU, GAME_SINGLE, GAME_MULTI 
}; 

private Connection mConnection; 
private ScoreDataSource mScoreDataSource; 
private GameEngine mGameEngine; 
private SplashScreen mSplash; 
private MainMenu mMenu; 
private State mState = State.SPLASH; 
private long mTime; 
private int mVersionID; 

/* Other stuff */ 

@Override 
public int describeContents() { 
    return 0; 
} 

@Override 
public void writeToParcel(Parcel out, int flags) { 
    out.writeString(mState.name()); 
    out.writeParcelable(mSplash, 0); 
    out.writeParcelable(mMenu, 0); 
} 

public static final Parcelable.Creator<FlowManager> CREATOR = new Parcelable.Creator<FlowManager>() { 
    public FlowManager createFromParcel(Parcel in) { 
     return new FlowManager(in); 
    } 

    public FlowManager[] newArray(int size) { 
     return new FlowManager[size]; 
    } 
}; 

private FlowManager(Parcel in) { 
    mConnection = new Connection(); 

    mState = State.valueOf(in.readString()); 
    mSplash = in.readParcelable(null); // Exception occurs here 
    mMenu = in.readParcelable(null); 
} 

} 

的FlowManager類有需要保存其他類的實例。那些我創建了Parselable的類,並且在恢復它們時我得到了錯誤。

我已經看到有關此錯誤的帖子,但它們都是用於在應用程序之間發送數據並且必須使用不同的ClassLoader。這是所有相同的應用程序。我是否需要設置我的ClassLoader,因爲它位於GLSurfaceView中?我如何找到我需要的ClassLoader?

+0

什麼** ** mSplash?你可以粘貼整個'FlowManager'類 – waqaslam 2012-03-13 20:15:44

+0

我增加了更多的'FlowManager'完整的類很長,有很多不相關的代碼。 mSplash只是另一個類,我有'公共類SplashScreen擴展BasicScreen實現Parcelable' – EmbMicro 2012-03-13 20:28:52

回答

5

更新您的FlowManager(Parcel in)如下:

private FlowManager(Parcel in) { 
    mConnection = new Connection(); 

    mState = State.valueOf(in.readString()); 
    mSplash = in.readParcelable(SplashScreen.class.getClassLoader()); 
    mMenu = in.readParcelable(MainMenu.class.getClassLoader()); 
}