I am getting this error:
Caused by: com.google.firebase.database.DatabaseException: Found conflicting getters for name: isAccessibilityFocusable
while trying to update my User.
The User class is like this
public class User {
#PrimaryKey
String userName;
String groupName;
int totalMoney;
boolean turn;
boolean hapyo;
boolean blind;
#Exclude
TextView textView;
#Exclude
Button bHapdiye,bChale,bShow,bHeram;
public Button getbHapdiye() {
return bHapdiye;
}
public void setbHapdiye(Button bHapdiye) {
this.bHapdiye = bHapdiye;
}
public Button getbChale() {
return bChale;
}
public void setbChale(Button bChale) {
this.bChale = bChale;
}
public Button getbShow() {
return bShow;
}
public void setbShow(Button bShow) {
this.bShow = bShow;
}
public Button getbHeram() {
return bHeram;
}
public void setbHeram(Button bHeram) {
this.bHeram = bHeram;
}
public TextView getTextView() {
return textView;
}
public void setTextView(TextView textView) {
this.textView = textView;
}
public boolean isBlind() {
return blind;
}
public void setBlind(boolean blind) {
this.blind = blind;
}
public boolean isHapyo() {
return hapyo;
}
public void setHapyo(boolean hapyo) {
this.hapyo = hapyo;
}
public boolean isTurn() {
return turn;
}
public void setTurn(boolean turn) {
this.turn = turn;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public int getTotalMoney() {
return totalMoney;
}
public void setTotalMoney(int totalMoney) {
this.totalMoney = totalMoney;
}
}
I am trying to update the User like this
final User user1 = userList.get(0);
user1.setTextView(tvUser1);
user1.setbChale(bChaleP1);
user1.setbHapdiye(bHapdiyeP1);
user1.setbHeram(bHeramP1);
user1.setbShow(bShowP1);
user1.setTurn(true);
setUsersTurn(user1.isTurn(),bHapdiyeP1,bChaleP1,bShowP1,bHeramP1);
setTurnInFirebase(user1);
The setTurnInFirebase method is like this
public void setTurnInFirebase(User user){
myRef.child("users").setValue(user);
}
So when I run the project, I get the above mentioned error. What could be the reason for this. Thankyou
Your user contains a TextView, which is a class that Firebase won't be able to serialize/deserialize.
To allow writing a class to the Firebase Database, make sure that it only contains properties of simple types or objects that you created: so called POJOs - Plain Old Java Objects.
Alternatively you can exclude the non-supported properties (such as the TextView) by annotating them:
#Exclude
public TextView getTextView() {
return textView;
}
#Exclude
public void setTextView(TextView textView) {
this.textView = textView;
}
Related
i know actually a lot of these kinds of questions, and i have searched on google but i can't find where the error is in my code.
I tried to send a request to fetch data, but it runs the onFailure method which reads "NumberFormatException: Empty string" and the data can't be displayed in the recyclerview, even though I'm also getting a json response as I wanted.
i got this response:
{
"kode":1,
"pesan":"Barang ditemukan",
"data":[
{
"Sat_1":"PT",
"Sat_2":"",
"Isi_2":"",
"KdBrg":"280349191",
"NmBrg":"SILICONE PACIFIER STEP 1A",
"Stock_Akhir":"0",
"Hrg":28000
}
]
}
my object model
public class ModelDataBarang {
private int Isi_2;
private int Isi_3;
private int Isi_4;
private String KdBrg;
private String NmBrg;
private String Sat_1;
private String Sat_2;
private String Sat_3;
private String Sat_4;
private String KdHrgList;
private double Stock_Akhir;
private double HrgJl11;
public double getHrgJl11() {
return HrgJl11;
}
public void setHrgJl11(double hrgJl11) {
HrgJl11 = hrgJl11;
}
private String Hrg;
public String getHrg() {
return Hrg;
}
public void setHrg(String hrg) {
Hrg = hrg;
}
public String getKdHrgList() {
return KdHrgList;
}
public void setKdHrgList(String kdHrgList) {
KdHrgList = kdHrgList;
}
public String getSat_3() {
return this.Sat_3;
}
public void setSat_3(String sat_3) {
this.Sat_3 = sat_3;
}
public String getSat_4() {
return this.Sat_4;
}
public void setSat_4(String sat_4) {
this.Sat_4 = sat_4;
}
public int getIsi_3() {
return this.Isi_3;
}
public void setIsi_3(int isi_3) {
this.Isi_3 = isi_3;
}
public int getIsi_4() {
return this.Isi_4;
}
public void setIsi_4(int isi_4) {
this.Isi_4 = isi_4;
}
public String getKdBrg() {
return this.KdBrg;
}
public void setKdBrg(String kdBrg) {
this.KdBrg = kdBrg;
}
public String getNmBrg() {
return this.NmBrg;
}
public void setNmBrg(String nmBrg) {
this.NmBrg = nmBrg;
}
public String getSat_1() {
return this.Sat_1;
}
public void setSat_1(String sat_1) {
this.Sat_1 = sat_1;
}
public String getSat_2() {
return this.Sat_2;
}
public void setSat_2(String sat_2) {
this.Sat_2 = sat_2;
}
public int getIsi_2() {
return this.Isi_2;
}
public void setIsi_2(int isi_2) {
this.Isi_2 = isi_2;
}
public double getStock_Akhir() {
return this.Stock_Akhir;
}
public void setStock_Akhir(double stock_Akhir) {
this.Stock_Akhir = stock_Akhir;
}
public String toString() {
return this.NmBrg;
}
}
my recyclerview data holder
ModelDataBarang modelBarangResto= listModel.get(position);
holder.tvKdBrg.setText(modelBarangResto.getKdBrg());
holder.tvNmBarang.setText(modelBarangResto.getNmBrg());
holder.tvHrgBrg.setText(String.valueOf(modelBarangResto.getHrg()));
all answers i will appreciate
Your model class values are not defined as per your response. Try to check and modify respective return type. You are getting this error because you have defined Isi_2 as int in your model class but in response you are getting empty string.
Replace this
private int Isi_2;
With this
private String Isi_2;
Hi guys I am trying to save objects with relations in Backendless via API. I have two classes namely Task and Reminder. A task can be associated with many reminders hence I want a 1:N relationship between the Task table and Reminder table in Backendless. My Task class is as follows:
public class Task {
public Date created;
public Date updated;
private List<Reminder> reminders = null;
private String ownerId;
#PrimaryKey
#NonNull
private String objectId;
#NonNull
private String taskTitle;
#NonNull
private Date deadline;
#NonNull
private int isCompleted = 0;
#NonNull
private int isExpired = 0;
public String getOwnerId() {
return ownerId;
}
public void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
#NonNull
public String getObjectId() {
return objectId;
}
public void setObjectId(#NonNull String objectId) {
this.objectId = objectId;
}
public List<Reminder> getReminders() {
return reminders;
}
public void setReminders(List<Reminder> reminders) {
this.reminders = reminders;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
#NonNull
public int getIsCompleted() {
return isCompleted;
}
public void setIsCompleted(#NonNull int isCompleted) {
this.isCompleted = isCompleted;
}
#NonNull
public int getIsExpired() {
return isExpired;
}
public void setIsExpired(#NonNull int isExpired) {
this.isExpired = isExpired;
}
public String getTaskTitle() {
return taskTitle;
}
public void setTaskTitle(String taskTitle) {
this.taskTitle = taskTitle;
}
public Date getDeadline() {
return deadline;
}
public void setDeadline(Date deadline) {
this.deadline = deadline;
}
}
Reminder Class:
public class Reminder {
private String title;
private Date time;
private String objectId;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getObjectId() {
return objectId;
}
public void setObjectId(String objectId) {
this.objectId = objectId;
}
}
I am saving the objects and setting up the relation as below:
public void saveTaskToServer(final Task task) {
List<Reminder> remindersList = new ArrayList<>();
remindersList = task.getReminders();
final List<Reminder> savedReminders = new ArrayList<>();
if(remindersList!=null && remindersList.size()!=0) {
for
(Reminder reminder : remindersList) {
reminder.setTitle(task.getTaskTitle());
Backendless.Persistence.save(reminder, new AsyncCallback<Reminder>() {
#Override
public void handleResponse(Reminder response) {
savedReminders.add(response);
}
#Override
public void handleFault(BackendlessFault fault) {
Log.i("error saving remidners", fault.toString());
}
});
}
}
Backendless.Persistence.save(task, new AsyncCallback<Task>() {
#Override
public void handleResponse(Task response) {
newTask = response;
Log.i("id is ", newTask.getObjectId());
insertTask(response);
snackbarMessage.postValue("Task Created Successfully.");
}
#Override
public void handleFault(BackendlessFault fault) {
Log.i("error", fault.getMessage());
}
});
Backendless.Persistence.of(Task.class).addRelation(task, "reminders", savedReminders, new AsyncCallback<Integer>() {
#Override
public void handleResponse(Integer response) {
Log.i("response", "added" + response);
newTask.setReminders(savedReminders);
}
#Override
public void handleFault(BackendlessFault fault) {
Log.i("response", "error" + fault.toString());
}
});
}
I have tried saving the relation using the tablename:Class:n instead of the parentColumnName. Also tried saving the objectids of the reminders instead of the reminder objects themselves.The task and reminder objects get saved properly in the backendless console in their respective tables but the reminder column in the Task table still remains empty and no relations get added. Relations count in the backendless call in Android Studio also returns 0. Any advice is really appreciated. I have been following this example.
My relations were not getting saved because I was using the async callbacks in backendless!! I dont know why I didnt see that before. Since the save calls were being made before the async callbacks could finish I was ending up with null values. Fixed it by making the calls synchronous and wrapping them in an async task.
solved
Android - Firebase - Getting Child of Child Data
how to view leaf nodes both children and grandchildren
E/data: {6640={first={sub3=dbms, m5=3, m2=2, sub2=dl, sub1=cis, m3=2, sub4=socio, m4=2, sub5=english, m1=4}}}
firebase data structure
the values i want are
the children inside 6640 eg : first and second
the grandchildren inside first eg : sub1--sub5 and m1-m5
the data above is a snapshot data snapshot from a query.. how do i access each values from the following snapshot.. i created a data module and used a for each loop like this
for (DataSnapshot post : dataSnapshot.getChildren())
{
trial_module m2 = post.getValue(trial_module.class);
Log.e("data",dataSnapshot.getValue().toString());
data2.add(m2);
}
do i need to create mutiple classes to hold data?
public class Result_module {
String sub1,sub2,sub3,sub4,sub5;
long m1,m2,m3,m4,m5;
public String getSub1() {
return sub1;
}
public void setSub1(String sub1) {
this.sub1 = sub1;
}
public String getSub2() {
return sub2;
}
public void setSub2(String sub2) {
this.sub2 = sub2;
}
public String getSub3() {
return sub3;
}
public void setSub3(String sub3) {
this.sub3 = sub3;
}
public String getSub4() {
return sub4;
}
public void setSub4(String sub4) {
this.sub4 = sub4;
}
public String getSub5() {
return sub5;
}
public void setSub5(String sub5) {
this.sub5 = sub5;
}
public long getM1() {
return m1;
}
public void setM1(long m1) {
this.m1 = m1;
}
public long getM2() {
return m2;
}
public void setM2(long m2) {
this.m2 = m2;
}
public long getM3() {
return m3;
}
public void setM3(long m3) {
this.m3 = m3;
}
public long getM4() {
return m4;
}
public void setM4(long m4) {
this.m4 = m4;
}
public long getM5() {
return m5;
}
public void setM5(long m5) {
this.m5 = m5;
}
}
How to use realm relationships using 2 RealmList, here the example.
Class Menu
public class Menu extends RealmObject {
#SerializedName("name")
private String name;
#SerializedName("module")
private String module;
#SerializedName("controller")
private String controller;
#SerializedName("parent_module")
private String parentModule;
#SerializedName("status")
private Boolean status;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public String getController() {
return controller;
}
public void setController(String controller) {
this.controller = controller;
}
public String getParentModule() {
return parentModule;
}
public void setParentModule(String parentModule) {
this.parentModule = parentModule;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
}
Class Privilege
public class Privilege extends RealmObject {
private String module;
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
}
and i'm using this method to save them.
#Override
public void saveMenuPrivilege(RealmList<Menu> menu, RealmList<Privilege> privileges) {
}
now what makes me confuse is, there is a condition where if the module in class Menu has the same module in class Privilege, then set the active field for that module in class Menu to be "true". How to do that? or i'm doing it wrong using the code above?
Thanks in advance
All ready have the answer, just testing all by myself. :D
I have 2 class one is login_class second is student_class which is showing details of student.
What i have to do is when i login. In response i get the students details like
student_name,student_srno,student_father_name,student_mother_name etc.
This is my bean(Getter Setter) class
package com.smartschoolapp;
public class Bean {
String username, password, srno, studentname, classname, sec, contact,
father_name, mother_name, dob;
public Bean(String username,String password,String srno,String studentname,String classname,String sec,String contact,String father_name,String mother_name,String dob) {
this.username=username;
this.password= password;
this.srno=srno;
this.studentname=studentname;
this.classname=classname;
this.sec=sec;
this.contact=contact;
this.father_name=father_name;
this.mother_name=mother_name;
this.dob =dob;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSrno() {
return srno;
}
public void setSrno(String srno) {
this.srno = srno;
}
public String getStudentname() {
return studentname;
}
public void setStudentname(String studentname) {
this.studentname = studentname;
}
public String getClassname() {
return classname;
}
public void setClassname(String classname) {
this.classname = classname;
}
public String getSec() {
return sec;
}
public void setSec(String sec) {
this.sec = sec;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getFather_name() {
return father_name;
}
public void setFather_name(String father_name) {
this.father_name = father_name;
}
public String getMother_name() {
return mother_name;
}
public void setMother_name(String mother_name) {
this.mother_name = mother_name;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public Bean() {
}
}
And this is my login_class where i add data of the student in list.
class login_class extends activity{
Bean beanobj;
List student_detail_list;
.....
{
String name = getting data from response;
......... so on
beanobj = new Bean();
beanobj.studentname(name);
beanobj.student_parent_name(parentname);
.............so on
}
order_list.add(beanobj); // the details to list
}
Now the next activity student_class where i want to show the student in listview
public class student_class extends Activity {
ListView student_listview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.student_list);
student_listview = (ListView) findViewById(R.id.student_listview);
}
}
*==>> in login_class i have created List student_detail_list how can i get it in my student_class class and retrieve data .
Thanks
There are a lot a ways to do that. 1.Recommended Solution : How to pass an object from one activity to another on Android you can serialize your objects and put it into the intent. This is the recommended solution but there are some problems here. If your data contains a lot of memory, it might crash your application in runtime.
2. You can save your array into the file, send file path to other activity as with URL. In the second activity read the file and create the array in second activity as well.
3. My favourite solution is create a singleton class for student array, reach the class in any activity you want. But you should be careful because singleton pattern has some issues by design also it will stay in memory all the time
Realize the "class Bean implements Parcelable". When go to "student_class" from "login_class", just put the "student bean data" inside the Intent. After going to student_class, you can get the "student bean data" from the intent, here the sample code:
Intent intent = new Intent(login_class.this, student_class.class)
intent.putParcelableArrayListExtra("content", student_detail_list);
startActivity(intent);
In "student_class":
student_detail_list = getIntent().getParcelableArrayListExtra("content");