im trying to create a user object when the user log in and save it in shared prefrences. the user object has name and last name which im retreiving from json object and a bitmap profile pic which im trying to get with piccaso (the line to the picture is also in the json object). i tryed it with volley and with asynctask in both cases i get the expeption.
my user model:
public class User{
private String name,lastName;
private Bitmap profilePicture;
Context context;
public User(JSONObject object , Context context){
this.context = context;
try {
this.name = object.getString("firstName");
this.lastName = object.getString("lastName");
this.profilePicture = Picasso.with(context).load(object.getString("image")).get();
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
and my volley request:
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Intent intent = new Intent(LoginActivityScreen.this, HomeActivityScreen.class);
SharedPreferences.Editor editor = preferences.edit();
RoomateModel model = new RoomateModel(response, context);
Gson gson = new Gson();
String json = gson.toJson(model);
editor.putString("USER", json);
editor.commit();
startActivity(intent);
}
}