我在课堂上有一个方法:
public MyClass readMyObject(Activity activity) {
MyClass myClass = null;
try {
myClass = new MyClass();
SharedPreferences prefs = activity.getApplicationContext().getSharedPreferences("myClass", Context.MODE_PRIVATE);
String preferences = prefs.getString("myClass", "0");
ObjectMapper mapper = new ObjectMapper();
byte[] byteTemp = mapper.readValue(preferences, byte[].class);
ByteArrayInputStream in = new ByteArrayInputStream(byteTemp);
ObjectInputStream is = new ObjectInputStream(in);
myClass = (MyClass) is.readObject();
} catch (JsonParseException e) {
} catch (IOException e) {
} catch (ClassNotFoundException e) {
}
return myClass;
}
以下是我得到的例外
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/fasterxml/jackson/databind/ObjectMapper;
我用:
我的应用程序的目标是Android 5.0。 谢谢!