Cannot find io/realm/RealmProxy - android

I have a problem similiar to Realm.io can't get examples to work.
I tried the fix that was written there, but it still doesn't work.
I created two Realmclasses inside my AndroidApp for my Data.
Class one is called "Fahrt":
#RealmClass
public class Fahrt extends RealmObject {
private String fahrtname;
private String fahrtzeitstempel;
private String fahrtfahrzeug;
private RealmList<Data> listData;
public String getFahrtname() {
return fahrtname;
}
public void setFahrtname(String fahrtname) {
this.fahrtname = fahrtname;
}
public String getFahrtzeitstempel() {
return fahrtzeitstempel;
}
public void setFahrtzeitstempel(String fahrtzeitstempel) {
this.fahrtzeitstempel = fahrtzeitstempel;
}
public String getFahrtfahrzeug() {
return fahrtfahrzeug;
}
public void setFahrtfahrzeug(String fahrtfahrzeug) {
this.fahrtfahrzeug = fahrtfahrzeug;
}
public RealmList<Data> getListData() {
return listData;
}
public void setListData(RealmList<Data> listData) {
this.listData = listData;
}
}
Class two is called "Data":
#RealmClass
public class Data extends RealmObject {
private String zeitstempel;
private String header;
private String canid;
private String data;
public String getZeitstempel() {
return zeitstempel;
}
public void setZeitstempel(String zeitstempel) {
this.zeitstempel = zeitstempel;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public String getCanid() {
return canid;
}
public void setCanid(String canid) {
this.canid = canid;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
I tried to store some data in this way.
//global declarations
private static String fahrtname;
private Realm realm;
private Fahrt aktuellefahrt;
private Data addData;
private static StringBuilder sb;
private String datensatz_string;
....
realm = Realm.getInstance(mContext);
//myPersistMethod
private void persist(byte[] message)
{
realm.beginTransaction();
aktuellefahrt = realm.where(Fahrt.class).equalTo("fahrtname", fahrtname).findFirst();
if(aktuellefahrt == null)
{
aktuellefahrt = realm.createObject(Fahrt.class);
aktuellefahrt.setFahrtname(fahrtname);
aktuellefahrt.setFahrtzeitstempel(fahrtname);
aktuellefahrt.setFahrtfahrzeug("testFahrzeug");
}
RealmList<Data> realmListData = aktuellefahrt.getRealmListData();
if(realmListData == null)
{
realmListData = new RealmList<>();
}
datensatz_string = new String(toBinary(message));
addData = realm.createObject(Data.class);
addData.setZeitstempel((datensatz_string.substring(0,16)));
addData.setHeader(datensatz_string.substring(16, 24));
addData.setCanid((datensatz_string.substring(24, 56)));
addData.setData((datensatz_string.substring(56)));
aktuellefahrt.getRealmListData().add(addData);
realm.commitTransaction();
}
...
I allways get the error:
Error:Execution failed for task ':app:transformClassesWithRealmTransformerForDebug'.
cannot find io/realm/DataRealmProxy: io.realm.DataRealmProxy found in io/realm/DataRealmProxy.class
What did I do wrong?

Related

Fetching json object from JSON string

I am new to Android and I am developing app which has server side functionality. I am getting response in JSON format.
My response is shown as this image.
I know how to parse json using Volley but I don't know hot to parse using GSON. Previous code of my app was written by some one else. Now I have to complete this code. but I do not know how he getting data from JSON string.
I need JSON arrays in different activity. Array response:
image
Here is some snaps of my code.
Code for adapter for activity one
topicListAdapter = new TopicListAdapter(TopicActivity.this,
myCourseListMain. getCourseArrayList().get(Integer.parseInt(course_position)).
getTopicListMain().getTopicDetailsArrayList(), flag);
listAlltopics.setAdapter(topicListAdapter);
in which I got list of topics
here is code for second activity list adapter
lessionListAdapter = new LessionListAdapter(LessionActivity.this,
myCourseListMain. getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain().getTopicDetailsArrayList().get(Integer.parseInt(topic_position)).getLessionArrayList(), flag);
by this code i got array of lession in second activity
Now I want sublession array in third activity but I don't know how to get it.
Here is what I tried
lessionListAdapter = new DummyAdapter(DummyTopicList.this,
myCourseListMain . getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain() . getTopicDetailsArrayList() .get(Integer.parseInt(topic_position)).
getLessionLIstMain() .getLessionLIstDetailArrayList().get(Integer.parseInt(lession_position)). , flag);
listAlllessions.setAdapter(lessionListAdapter);
Here are some other classes which helpful to you for understand
public class MyCourseListMain {
#SerializedName("data")
private ArrayList<Course> courseArrayList;
public ArrayList<Course> getCourseArrayList() {
return courseArrayList;
}
public void setCourseArrayList(ArrayList<Course> courseArrayList) {
this.courseArrayList = courseArrayList;
}
}
class for course
public class Course {
#SerializedName("img")
private String img;
#SerializedName("title")
private String title;
#SerializedName("institute_id")
private String institute_id;
#SerializedName("institute_name")
private String institute_name;
#SerializedName("expired")
private String expired;
#SerializedName("status")
private String status;
#SerializedName("subscribe_box")
private String subscribe_box;
#SerializedName("expire_on")
private String expire_on;
#SerializedName("item_id")
private String item_id;
#SerializedName("rated")
private String rated;
private TopicListMain topicListMain;
public String getRated() {
return rated;
}
public void setRated(String rated) {
this.rated = rated;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getInstitute_id() {
return institute_id;
}
public void setInstitute_id(String institute_id) {
this.institute_id = institute_id;
}
public String getInstitute_name() {
return institute_name;
}
public void setInstitute_name(String institute_name) {
this.institute_name = institute_name;
}
public String getExpired() {
return expired;
}
public void setExpired(String expired) {
this.expired = expired;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSubscribe_box() {
return subscribe_box;
}
public void setSubscribe_box(String subscribe_box) {
this.subscribe_box = subscribe_box;
}
public String getExpire_on() {
return expire_on;
}
public void setExpire_on(String expire_on) {
this.expire_on = expire_on;
}
public String getItem_id() {
return item_id;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
}
public TopicListMain getTopicListMain() {
return topicListMain;
}
public void setTopicListMain(TopicListMain topicListMain) {
this.topicListMain = topicListMain; } }
class for topiclist_main
public class TopicListMain {
#SerializedName("data")
private ArrayList<TopicDetails> topicDetailsArrayList;
public ArrayList<TopicDetails> getTopicDetailsArrayList() {
return topicDetailsArrayList;
}
public void setTopicDetailsArrayList(ArrayList<TopicDetails> topicDetailsArrayList) {
this.topicDetailsArrayList = topicDetailsArrayList; }}
class for topic details
public class TopicDetails
{
#SerializedName("topic_id")
private String topic_id;
#SerializedName("title")
private String title;
#SerializedName("locked")
private String locked;
#SerializedName("lessons")
private ArrayList<Lession> lessionArrayList;
private LessionLIstMain lessionLIstMain;
public LessionLIstMain getLessionLIstMain() {
return lessionLIstMain;
}
public void setLessionLIstMain(LessionLIstMain lessionLIstMain) {
this.lessionLIstMain = lessionLIstMain;
}
public String getTopic_id() {
return topic_id;
}
public void setTopic_id(String topic_id) {
this.topic_id = topic_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocked() {
return locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
public ArrayList<Lession> getLessionArrayList() {
return lessionArrayList;
}
public void setLessionArrayList(ArrayList<Lession> lessionArrayList) {
this.lessionArrayList = lessionArrayList; }}
https://github.com/google/gson
Make your object have same construct with your data which you got.And
YourObject val = new Gson().fromJson(new String(YourString.getBytes("ISO-8859-1"),
"UTF-8"), YourObject.class);
finally i got my solution by below code.
lessionListAdapter = new DummyAdapter(DummyTopicList.this,
myCourseListMain . getCourseArrayList(). get(Integer.parseInt(course_position)).
getTopicListMain() . getTopicDetailsArrayList() .get(Integer.parseInt(topic_position)).
getLessionArrayList().get(Integer.parseInt((lession_position))).getLessionLIstDetailArrayList() , flag);
listAlllessions.setAdapter(lessionListAdapter);
i also made some few classes to handle json array.
public class SubLessionDetail {
#SerializedName("lesson_id")
private String lession_id;
#SerializedName("title")
private String title;
#SerializedName("locked")
private String locked;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocked() {
return locked;
}
public void setLocked(String locked) {
this.locked = locked;
}
public String getLession_id() {
return lession_id;
}
public void setLession_id(String lession_id) {
this.lession_id = lession_id;
}
}

Not receiving data from server using Retrofit 2

I am trying to retrieve Reddit information from a particular subreddit using Retrofit 2. I have followed many tutorials and videos and my code seems to be correct from my perspective but I only manage to have null objects in my model class. I have the permission for internet in the Manifest.
This is a link the JSON I am working with HERE
MainActivity
public class MainActivity extends AppCompatActivity
{
TextView mTextView;
Data mData;
private static final String TAG = "Battlestations";
#Override
protected void onCreate(Bundle savedInstanceState)
{
mTextView = (TextView) findViewById(R.id.test_view);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Call<Data> serviceCall = Service.getDesktopService().desks();
serviceCall.enqueue(new Callback<Data>()
{
#Override
public void onResponse(Call<Data> call, Response<Data> response)
{
Log.d("Reponce","return");
Log.i(TAG, "Response is " + mData.getChildren());
}
#Override
public void onFailure(Call<Data> call, Throwable t)
{
}
});
}
}
Api/Service Class
public class Service
{
private static final String BASE_URL = "https://www.reddit.com/r/";
private static DeskInterface mRetrofit;
public static DeskInterface getDesktopService()
{
if(mRetrofit == null)
{
Retrofit build = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
mRetrofit = build.create(DeskInterface.class);
}
return mRetrofit;
}
public interface DeskInterface
{
#GET("battlestations/hot/.json")
Call<Data> desks();
}
}
Data
public class Data
{
private List<Child> children = null;
public List<Child> getChildren()
{
return children;
}
public void setChildren(List<Child> children)
{
this.children = children;
}
}
Child
public class Child
{
private Data_ data;
public Data_ getData()
{
return data;
}
public void setData(Data_ data)
{
this.data = data;
}
}
Data_
public class Data_
{
private String subreddit;
private Integer score;
private String author;
private String subredditNamePrefixed;
private String url;
private String title;
public String getSubreddit()
{
return subreddit;
}
public void setSubreddit(String subreddit)
{
this.subreddit = subreddit;
}
public Integer getScore()
{
return score;
}
public void setScore(Integer score)
{
this.score = score;
}
public String getAuthor()
{
return author;
}
public void setAuthor(String author)
{
this.author = author;
}
public String getSubredditNamePrefixed()
{
return subredditNamePrefixed;
}
public void setSubredditNamePrefixed(String subredditNamePrefixed)
{
this.subredditNamePrefixed = subredditNamePrefixed;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
this.url = url;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
}
You need to add mData = response.body() in onResponse() (also check response.isSuccessful() first)
The problem is that your Data does not correspond with Reddit JSON. Your Data class
public class Data {
private List<Child> children = null;
}
does not match with the given json, which is:
{
"kind":"listing",
"data":{
"modhash":"...",
"children":[...],
"after":"...",
"before":"..."
}
}
Retrofit automagically convert from json to java but only if the mapping is correct.
A correct Java class would be:
public class Subreddit {
String kind;
Data data;
}
public class Data{
String modhash;
List<Child> children;
String after;
String before;
}
and then modify desks method interface to
Call<Subreddit> desks();
You would have to go recursively for the entire depth of the JSON to get the right mapping.
But before you get to work, just replace your Retrofit interface:
public interface DeskInterface{
#GET("battlestations/hot/.json")
Call<Data> desks();
}
with:
public interface DeskInterface{
#GET("battlestations/hot/.json")
Call<JsonObject> desks();
}
and it should return something. If is still null, then further investigation is needed. If it returns a valid response(some json text) then copy/paste that subreddit to this website where it converts all the json to a valid Java class

How to pass arraylist of class from one activity to another activity onclick of adapter Textview

This my class which implements Serializable and onclick of one textview I am passing arraylist from one activity to other activity, but while retrieving there some problem please help out if someone aware of this type of issue.
public class RoomCategoryList implements Serializable {
#SerializedName("roomCode")
#Expose
private String roomCode;
#SerializedName("roomCategoryCode")
#Expose
private String roomCategoryCode;
#SerializedName("roomCategoryName")
#Expose
private String roomCategoryName;
#SerializedName("roomType")
#Expose
private String roomType;
#SerializedName("boardData")
#Expose
private BoardData boardData;
#SerializedName("roomImages")
#Expose
private List<String> roomImages = new ArrayList<String>();
#SerializedName("roomAllotment")
#Expose
private int roomAllotment;
#SerializedName("listPrice")
#Expose
private double listPrice;
#SerializedName("offerPrice")
#Expose
private double offerPrice;
#SerializedName("refundable")
#Expose
private boolean refundable;
#SerializedName("roomCategoryAdjustment")
#Expose
private int roomCategoryAdjustment;
#SerializedName("cancelPolicy")
#Expose
private List<CancelPolicy> cancelPolicy = new ArrayList<CancelPolicy>();
#SerializedName("bedBankAdditionalData")
#Expose
private String bedBankAdditionalData;
#SerializedName("hotelInformations")
#Expose
private List<HotelInformation> hotelInformations = new ArrayList<HotelInformation>();
#SerializedName("facilities")
#Expose
private List<Facility> facilities = new ArrayList<Facility>();
#SerializedName("currency")
#Expose
private String currency;
public String getRoomCode() {
return roomCode;
}
public void setRoomCode(String roomCode) {
this.roomCode = roomCode;
}
public String getRoomCategoryCode() {
return roomCategoryCode;
}
public void setRoomCategoryCode(String roomCategoryCode) {
this.roomCategoryCode = roomCategoryCode;
}
public String getRoomCategoryName() {
return roomCategoryName;
}
public void setRoomCategoryName(String roomCategoryName) {
this.roomCategoryName = roomCategoryName;
}
public String getRoomType() {
return roomType;
}
public void setRoomType(String roomType) {
this.roomType = roomType;
}
public BoardData getBoardData() {
return boardData;
}
public void setBoardData(BoardData boardData) {
this.boardData = boardData;
}
public List<String> getRoomImages() {
return roomImages;
}
public void setRoomImages(List<String> roomImages) {
this.roomImages = roomImages;
}
public int getRoomAllotment() {
return roomAllotment;
}
public void setRoomAllotment(int roomAllotment) {
this.roomAllotment = roomAllotment;
}
public double getOfferPrice() {
return offerPrice;
}
public void setOfferPrice(double offerPrice) {
this.offerPrice = offerPrice;
}
public double getListPrice() {
return listPrice;
}
public void setListPrice(double listPrice) {
this.listPrice = listPrice;
}
public boolean isRefundable() {
return refundable;
}
public void setRefundable(boolean refundable) {
this.refundable = refundable;
}
public int getRoomCategoryAdjustment() {
return roomCategoryAdjustment;
}
public void setRoomCategoryAdjustment(int roomCategoryAdjustment) {
this.roomCategoryAdjustment = roomCategoryAdjustment;
}
public List<CancelPolicy> getCancelPolicy() {
return cancelPolicy;
}
public void setCancelPolicy(List<CancelPolicy> cancelPolicy) {
this.cancelPolicy = cancelPolicy;
}
public String getBedBankAdditionalData() {
return bedBankAdditionalData;
}
public void setBedBankAdditionalData(String bedBankAdditionalData) {
this.bedBankAdditionalData = bedBankAdditionalData;
}
public List<HotelInformation> getHotelInformations() {
return hotelInformations;
}
public void setHotelInformations(List<HotelInformation> hotelInformations) {
this.hotelInformations = hotelInformations;
}
public List<Facility> getFacilities() {
return facilities;
}
public void setFacilities(List<Facility> facilities) {
this.facilities = facilities;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
}
I want to send this arraylist to another activity, any help
For passing Arraylist from one activity A to another activity B, you can refer following code.
In Activity A:
Intent intent = new Intent(mContext, YourActivity.class);
Bundle bundleList = new Bundle();
bundleList.putSerializable("your string", (Serializable) mArrayList);
intent.putExtras(bundleList);
In Activity B:
Intent intent = getIntent();`enter code here`
ArrayList<String> list = (ArrayList<String>)intent.getSerializableExtra("your string");
For better performance, you should use Parceleable instead of Serializable
You can pass an ArrayList the same way, if the E type is Serializable.
Example:
putExtra first Activity
ArrayList<String> myList = new ArrayList<String>();
intent.putExtra("mylist", myList)
getIntent in second Activity:
ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("mylist");

I get an error when I try to get a responseObj from Json using Gson. FATAL EXCEPTION: OkHttp Dispatcher NumberFormatException: Invalid double: ""

New to using okhttp and Gson. I am practicing by creating a List View that will display information from Rotten Tomatoes API
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import com.google.gson.Gson;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
ListView listView;
Response responseObj;
CustomAdapter adapter;
String url = "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=9htuhtcb4ymusd73d4z6jxcj";
Gson gson;
OkHttpClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.myList);
client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
#Override
public void onFailure(Request request, IOException e) {
}
#Override
public void onResponse(com.squareup.okhttp.Response response) throws IOException {
String responseStr = response.body().string();
gson = new Gson();
**responseObj = gson.fromJson(responseStr,Response.class);**
adapter = new CustomAdapter(MainActivity.this, responseObj.getMovies());
listView.setAdapter(adapter);
}
});
}
}
This is the Error I get for line 44
FATAL EXCEPTION: OkHttp Dispatcher
com.google.gson.JsonSyntaxException: java.lang.NumberFormatException:
Invalid double: ""
public class Response {
private String link_template;
/**
* id : 771312089
* title : The Hunger Games: Mockingjay - Part 2
* year : 2015
* mpaa_rating : PG-13
* runtime : 136
* critics_consensus :
* release_dates : {"theater":"2015-11-20"}
* ratings : {"critics_rating":"Fresh","critics_score":70,"audience_rating":"Upright","audience_score":71}
* synopsis : The second half of Suzanne Collins' final Hunger Games book is adapted in this Lionsgate production. ~ Jeremy Wheeler, Rovi
* posters : {"thumbnail":"http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg","profile":"http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg","detailed":"http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg","original":"http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg"}
* abridged_cast : [{"name":"Jennifer Lawrence","id":"770800260","characters":["Katniss Everdeen"]},{"name":"Julianne Moore","id":"162654248","characters":["President Alma Coin"]},{"name":"Gwendoline Christie","id":"771060732","characters":["Commander Lyme"]},{"name":"Josh Hutcherson","id":"162654356","characters":["Peeta Mellark"]},{"name":"Robert Knepper","id":"162707688","characters":["Antonius"]}]
* links : {"self":"http://api.rottentomatoes.com/api/public/v1.0/movies/771312089.json","alternate":"http://www.rottentomatoes.com/m/the_hunger_games_mockingjay_part_2/","cast":"http://api.rottentomatoes.com/api/public/v1.0/movies/771312089/cast.json","reviews":"http://api.rottentomatoes.com/api/public/v1.0/movies/771312089/reviews.json","similar":"http://api.rottentomatoes.com/api/public/v1.0/movies/771312089/similar.json"}
*/
private List<MoviesEntity> movies;
public void setLinks(LinksEntity links) {
this.links = links;
}
public void setLink_template(String link_template) {
this.link_template = link_template;
}
public void setMovies(List<MoviesEntity> movies) {
this.movies = movies;
}
public LinksEntity getLinks() {
return links;
}
public String getLink_template() {
return link_template;
}
public List<MoviesEntity> getMovies() {
return movies;
}
public static class LinksEntity {
private String self;
private String alternate;
public void setSelf(String self) {
this.self = self;
}
public void setAlternate(String alternate) {
this.alternate = alternate;
}
public String getSelf() {
return self;
}
public String getAlternate() {
return alternate;
}
}
public static class MoviesEntity {
private String id;
private String title;
private int year;
private String mpaa_rating;
private int runtime;
private String critics_consensus;
/**
* theater : 2015-11-20
*/
private ReleaseDatesEntity release_dates;
/**
* critics_rating : Fresh
* critics_score : 70
* audience_rating : Upright
* audience_score : 71
*/
private RatingsEntity ratings;
private String synopsis;
/**
* thumbnail : http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg
* profile : http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg
* detailed : http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg
* original : http://resizing.flixster.com/nim-D7-9jGbUZS5wczNes_PmWyI=/53x81/dkpu1ddg7pbsk.cloudfront.net/movie/11/20/29/11202951_ori.jpg
*/
private PostersEntity posters;
/**
* self : http://api.rottentomatoes.com/api/public/v1.0/movies/771312089.json
* alternate : http://www.rottentomatoes.com/m/the_hunger_games_mockingjay_part_2/
* cast : http://api.rottentomatoes.com/api/public/v1.0/movies/771312089/cast.json
* reviews : http://api.rottentomatoes.com/api/public/v1.0/movies/771312089/reviews.json
* similar : http://api.rottentomatoes.com/api/public/v1.0/movies/771312089/similar.json
*/
private LinksEntity links;
/**
* name : Jennifer Lawrence
* id : 770800260
* characters : ["Katniss Everdeen"]
*/
private List<AbridgedCastEntity> abridged_cast;
public void setId(String id) {
this.id = id;
}
public void setTitle(String title) {
this.title = title;
}
public void setYear(int year) {
this.year = year;
}
public void setMpaa_rating(String mpaa_rating) {
this.mpaa_rating = mpaa_rating;
}
public void setRuntime(int runtime) {
this.runtime = runtime;
}
public void setCritics_consensus(String critics_consensus) {
this.critics_consensus = critics_consensus;
}
public void setRelease_dates(ReleaseDatesEntity release_dates) {
this.release_dates = release_dates;
}
public void setRatings(RatingsEntity ratings) {
this.ratings = ratings;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public void setPosters(PostersEntity posters) {
this.posters = posters;
}
public void setLinks(LinksEntity links) {
this.links = links;
}
public void setAbridged_cast(List<AbridgedCastEntity> abridged_cast) {
this.abridged_cast = abridged_cast;
}
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public int getYear() {
return year;
}
public String getMpaa_rating() {
return mpaa_rating;
}
public int getRuntime() {
return runtime;
}
public String getCritics_consensus() {
return critics_consensus;
}
public ReleaseDatesEntity getRelease_dates() {
return release_dates;
}
public RatingsEntity getRatings() {
return ratings;
}
public String getSynopsis() {
return synopsis;
}
public PostersEntity getPosters() {
return posters;
}
public LinksEntity getLinks() {
return links;
}
public List<AbridgedCastEntity> getAbridged_cast() {
return abridged_cast;
}
public static class ReleaseDatesEntity {
private String theater;
public void setTheater(String theater) {
this.theater = theater;
}
public String getTheater() {
return theater;
}
}
public static class RatingsEntity {
private String critics_rating;
private int critics_score;
private String audience_rating;
private int audience_score;
public void setCritics_rating(String critics_rating) {
this.critics_rating = critics_rating;
}
public void setCritics_score(int critics_score) {
this.critics_score = critics_score;
}
public void setAudience_rating(String audience_rating) {
this.audience_rating = audience_rating;
}
public void setAudience_score(int audience_score) {
this.audience_score = audience_score;
}
public String getCritics_rating() {
return critics_rating;
}
public int getCritics_score() {
return critics_score;
}
public String getAudience_rating() {
return audience_rating;
}
public int getAudience_score() {
return audience_score;
}
}
public static class PostersEntity {
private String thumbnail;
private String profile;
private String detailed;
private String original;
public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}
public void setProfile(String profile) {
this.profile = profile;
}
public void setDetailed(String detailed) {
this.detailed = detailed;
}
public void setOriginal(String original) {
this.original = original;
}
public String getThumbnail() {
return thumbnail;
}
public String getProfile() {
return profile;
}
public String getDetailed() {
return detailed;
}
public String getOriginal() {
return original;
}
}
public static class LinksEntity {
private String self;
private String alternate;
private String cast;
private String reviews;
private String similar;
public void setSelf(String self) {
this.self = self;
}
public void setAlternate(String alternate) {
this.alternate = alternate;
}
public void setCast(String cast) {
this.cast = cast;
}
public void setReviews(String reviews) {
this.reviews = reviews;
}
public void setSimilar(String similar) {
this.similar = similar;
}
public String getSelf() {
return self;
}
public String getAlternate() {
return alternate;
}
public String getCast() {
return cast;
}
public String getReviews() {
return reviews;
}
public String getSimilar() {
return similar;
}
}
public static class AbridgedCastEntity {
private String name;
private String id;
private List<String> characters;
public void setName(String name) {
this.name = name;
}
public void setId(String id) {
this.id = id;
}
public void setCharacters(List<String> characters) {
this.characters = characters;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public List<String> getCharacters() {
return characters;
}
}
}
}
package com.example.nano1.gsonexample;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
public class CustomAdapter extends BaseAdapter {
private List<Response.MoviesEntity> mMovieItem;
private Context context;
private LayoutInflater inflater;
public CustomAdapter(Context context, List<Response.MoviesEntity> mMovieItem) {
this.context = context;
this.mMovieItem = mMovieItem;
}
#Override
public int getCount() {
return mMovieItem.size();
}
#Override
public Object getItem(int position) {
return mMovieItem.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.each_list_item, parent, false);
Response.MoviesEntity item = (Response.MoviesEntity) getItem(position);
ImageView thumbnail = (ImageView) rowView.findViewById(R.id.thumnnail);
TextView title = (TextView) rowView.findViewById(R.id.title);
TextView rating = (TextView) rowView.findViewById(R.id.rating);
String imageURL = item.getPosters().getOriginal();
Picasso.with(context).load(imageURL).into(thumbnail);
title.setText(item.getTitle());
rating.setText(item.getRatings().getAudience_rating());
return rowView;
}
}
in the declared classes above you have members of type int now in the response you are getting values for these members as empty string "" which is not allowed, it should be an integer. that makes the exception, you either:
1- change member type to String, and handle empty string as 0 in the setters/getters
or
2- ask the back-end team to send correct data
or
3- use a custom TypedAdapter in the Gson converter to handle integers when they have empty string
P.S: i am aware the sample json does not contain empty strings but on the real call on the service, you might have an empty strings for integer members

How to Save and retrieve Custom Arrailist from Shared Preference

I want to Store and retrieve my Custom object Arralist from Sharedpreference,i have tried but getting Compiletime Error
Could any one help?
Code:
#Override protected void onPause() {
List<Movie> movieList;
super.onPause();
//save the movie list to preference
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
Editor editor = preferences.edit();
try {
editor.putString("movies", org.apache.pig.impl.util.ObjectSerializer.serialize(movieList));
} catch (IOException e) {
e.printStackTrace();
}
editor.commit();
}
}
Here is the Model class which is to be :
public class Movie implements Serializable {
private static final long serialVersionUID = 1L;
private String MovieName;
private String MovieActor;
private String MovieActress;
private String MovieDirector;
private String MovieImage;
private String MovieDescription;
private String MovieWatchLink;
public String getMovieName() {
return MovieName;
}
public void setMovieName(String movieName) {
MovieName = movieName;
}
public String getMovieActor() {
return MovieActor;
}
public void setMovieActor(String movieActor) {
MovieActor = movieActor;
}
public String getMovieActress() {
return MovieActress;
}
public void setMovieActress(String movieActress) {
MovieActress = movieActress;
}
public String getMovieDirector() {
return MovieDirector;
}
public void setMovieDirector(String movieDirector) {
MovieDirector = movieDirector;
}
public String getMovieImage() {
return MovieImage;
}
public void setMovieImage(String movieImage) {
MovieImage = movieImage;
}
public String getMovieDescription() {
return MovieDescription;
}
public void setMovieDescription(String movieDescription) {
MovieDescription = movieDescription;
}
public String getMovieWatchLink() {
return MovieWatchLink;
}
public void setMovieWatchLink(String movieWatchLink) {
MovieWatchLink = movieWatchLink;
}
Compile time Error:
The method serialize(Serializable) in the type ObjectSerializer is not applicable for the
arguments (List<Movie>)
List<> does not implement the Serializable interface. (Movie does).
You could try ArrayList (cannot try it out here)
Instead of List<Movie> movieList; use ArrayList<Movie> movieList;

Categories

Resources