Firebase: No properties to serialise - Android - java

I'm running into problems trying to read and write data to/from my Firebase realtime database. I have a register and login activity. When I register a user, I want to authenticate them and add the User's data to the database.
Here is my User class:
public class myUser {
public static boolean onlineStatus;
public static int userAge;
public static String userGender;
public static String userId;
public static String userName;
public myUser() {
}
//Default constructor will have/set the default info for the users such as:
//(auto generated) id name, age, and gender initialised at creation time
public myUser(boolean onlineStatus, int userAge, String userGender, String userId, String userName ) {
this.onlineStatus = onlineStatus;
this.userAge = userAge;
this.userGender = userGender;
this.userId = userId;
this.userName = userName;
}
//Getters
public static String getUserId() {
return userId;
}
public static String getUserName() {
return userName;
}
public static int getUserAge() {
return userAge;
}
public static String getUserGender() {
return userGender;
}
public static boolean getOnlineStatus() {
return onlineStatus;
}
//Setters
public static void setOnlineStatusTrue() {
onlineStatus = true;
}
public static void setOnlineStatusFalse() {
onlineStatus = false;
}
}
Now when I set a Database reference to my User object like so:
String id = databaseUsers.push().getKey();
myUser userRef = new myUser(onlineStatus, age, gender, id, name );
databaseUsers.setValue(userRef);
Now when I go register a user in my register activity my App crashes and I get the following error:
No properties to serialise:
(https://puu.sh/A08NT.png
I've also added some ProGuard rules but I still get the same error.
-keepattributes Signature
-keepclassmembers class com.example.teamc.friendfinder.** {
*;
}
All I would like to do is to register a user, add them to the database and set their online status to False. Then when the user signs in I'd like to set it to True so I'm able to get their online status activity and update the UI.

To solve your problem, please use the following steps.
Change all your fileds from your model class from public static to private.
private boolean onlineStatus;
private int userAge;
private String userGender;
private String userId;
private String userName;
Change all your setters and getters from your model class from public static to only public.

Related

Variable "Name" is not readable, how can I fix it?

I was inserting some code to make a registration form, but iIfound this
class User {
private String Nama;
private String Kelas;
private int NIM;
public String getNama{
return Nama;
}
public String setNama{
}
}
The error message was all "variable is never read". Can someone explain why there is a message on this, and how I can fix it?
Though it is not clear where you use your codes, but the following is a java model class, with setter and getter method. Even it is not the direct answer of you question, but I have used this types of model class in my projects, one can find the idea of setter and getter from the following user class.
For using in various purposes You can create your User class as follows with constructors and setter and getter methods :
public class User {
private String Nama;
private String Kelas;
private int NIM;
public User() {
}
public User(String nama, String kelas, int NIM) {
Nama = nama;
Kelas = kelas;
this.NIM = NIM;
}
public String getNama() {
return Nama;
}
public void setNama(String nama) {
Nama = nama;
}
public String getKelas() {
return Kelas;
}
public void setKelas(String kelas) {
Kelas = kelas;
}
public int getNIM() {
return NIM;
}
public void setNIM(int NIM) {
this.NIM = NIM;
}
}

Unable to get the list of followers in twitter using Fabric Android

I am using Fabric sdk for Twitter. In this I am able to make login request as it's described in its document. Now I wan't to get list of follower of logged in user and show in a listview.I have tried many links but these links not work for me
How to get list of followers using Twitter Fabric Android?
Can't get List of followers in Twitter using Fabric
then i tried this code but still my app crashed everytime when i run it.
class MyTwitterApiClient extends TwitterApiClient
{
public MyTwitterApiClient(TwitterSession session)
{
super(session);
}
public CustomService getCustomService() {
return getService(CustomService.class);
}
interface CustomService {
#GET("/1.1/followers/list.json")
Call<User> show(#Query("user_id") Long userId, #Query("screen_name") String
var, #Query("skip_status") Boolean var1, #Query("include_user_entities") Boolean var2, #Query("count") Integer var3, Callback < Followers > cb);
}
}
Called like this:
new MyTwitterApiClient(session).getCustomService().show(userID, null, true, true, 100, new Callback<User>() {
#Override
public void success(Result<User> result) {
LogUtils.LOGI("Get success",result.toString());
}
#Override
public void failure(TwitterException e) {
hideProgressDialog();
}
});
By this method I am not able to get followers.
Thanks.
You have to use updated version Retrofit2.
Write following code in your gradle file:-
compile 'com.squareup.retrofit2:retrofit:2.1.0'
Try Following code :
Interface:
public interface TwitterFollowersService {
/**
* This method id used to get the List of TWITTER FOLLOWERS.
*
* #param userId Get UserId after login and pass it here
* #param var Send Current user screen name
* #param var1 Weather to skip status accept TRUE/FALSE
* #param var2 Weather to include Entities accept TRUE/FALSE
* #param var3 Count to get number of response
* #return Call object of type FOLLOWERS.
*/
#GET("/1.1/followers/list.json")
Call<Response> show(#Query("user_id") Long userId, #Query("screen_name") String
var, #Query("skip_status") Boolean var1, #Query("include_user_entities") Boolean
var2, #Query("count") Integer var3);
}
use this code in you class/Activity:
private Callback<TwitterSession> authorizeCallback = new Callback<TwitterSession>() {
#Override
public void success(com.twitter.sdk.android.core.Result<TwitterSession> result) {
TwitterSession session = Twitter.getSessionManager().getActiveSession();
if (isNetworkAvailable(this)) {
if (session != null) {
TwitterApiServices apiclients = new TwitterApiServices(session);
Call<Response> call = apiclients.getCustomService().show(result.data.getUserId(), result.data.getUserName(), true, false, 100);
call.enqueue(new retrofit2.Callback<Response>() {
#Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
if (response.body().getUsers().size() > 0) {
ArrayList<TwitterFollowersList> twitterFollowersList = new ArrayList<>();
for (int i = 0; i < response.body().getUsers().size(); i++) {
TwitterFollowersList twitterFollowers = new TwitterFollowersList();
twitterFollowers.setId(response.body().getUsers().get(i).getId());
twitterFollowers.setName(response.body().getUsers().get(i).getName());
twitterFollowers.setProfile_image_url(response.body().getUsers().get(i).getProfile_image_url());
Log.d("TwitterFollowers", "ID: " + response.body().getUsers().get(i).getId() + " Name: " + response.body().getUsers().get(i).getName() + " ProfileImageURL: " + response.body().getUsers().get(i).getProfile_image_url());
twitterFollowersList.add(twitterFollowers);
}
//Upload twitter folowers to server.
uploadUserTwitterContacts(twitterFollowersList);
}
}
#Override
public void onFailure(Call<Response> call, Throwable t) {
showToast(this, "Unable to get response. Try Again!!");
}
});
} else {
showToast(this, getResources().getString(R.string.server_error));
}
} else {
showToast(this, getResources().getString(R.string.no_internet));
}
}
#Override
public void failure(TwitterException e) {
showToast(this, getResources().getString(R.string.server_error));
}
};
Use these following model classes as a response, and make their getter setter:
1)
public class Response {
#SerializedName("users")
private List<Users> users;
private String next_cursor;
private String previous_cursor_str;
private String previous_cursor;
private String next_cursor_str;
}
2)
public class Users {
private String location;
private String default_profile;
private String profile_background_tile;
private String statuses_count;
private String live_following;
private String lang;
private String profile_link_color;
private String profile_banner_url;
private String id;
private String following;
private String muting;
//private String protected;
private String favourites_count;
private String profile_text_color;
private String description;
private String verified;
private String contributors_enabled;
private String profile_sidebar_border_color;
private String name;
private String profile_background_color;
private String created_at;
private String is_translation_enabled;
private String default_profile_image;
private String followers_count;
private String has_extended_profile;
private String profile_image_url_https;
private String geo_enabled;
//private Status status;
private String profile_background_image_url;
private String profile_background_image_url_https;
private String follow_request_sent;
//private Entities entities;
private String url;
private String utc_offset;
private String time_zone;
private String blocking;
private String notifications;
private String profile_use_background_image;
private String friends_count;
private String blocked_by;
private String profile_sidebar_fill_color;
private String screen_name;
private String id_str;
private String profile_image_url;
private String listed_count;
private String is_translator;
}
Hope it will help you. :)

Cannot make a static reference to the non-static field in a java class

public class College {
public String collegename;
public String branch;
public String username;
public String password;
public College(String college,String branch,String user, String pass)
{
College.collegename = college;
College.branch= branch;
College.username= user;
College.password= pass;
}
}
this is my class and the error that is occouring is cannot make a static reference to the non-static field. Please tell me what is the problem and let me know how to slove it.
Thanks in advace.
You're passing the constructor the wrong instances: you have to refer to class' instances as "this".
Correct syntax:
public College(String college,String branch,String user, String pass)
{
this.collegename = college;
this.branch= branch;
this.username= user;
this.password= pass;
}
You are declaring class level variables and using it like static members.
Try
public class College {
public String collegename;
public String branch;
public String username;
public String password;
public college(String college,String branch,String user, String pass)
{
this.collegename = college;
this.branch= branch;
this.username= user;
this.password= pass;
}
}
this keyword is use to refer class variables.
Edit:
If you want to use as mentioned in comment.
public class College {
String collegename;
String branch;
String username;
String password;
private static College instance = null;
protected College() {
// Exists only to defeat instantiation.
}
public static College getInstance() {
if(instance == null) {
instance = new College();
}
return instance;
}
public void SetData(String collegeName, String branch, String userName, String password)
{
this.collegename = collegeName;
this.branch= branch;
this.username= userName;
this.password= password;
}
public String GetCollegeName()
{
return this.collegename;
}
// So on...
}
Set all data first anywhere in any class like,
College.getInstance().SetData("abcCollege","abcBranch","username","password");
Use it in another class like,
ArrayList<NameValuePair>dataToSend = new ArrayList<>(); dataToSend.add(new BasicNameValuePair("collegename", College.getInstance().GetCollegeName()));
Or simply make instance of College.
College college = new College("abcCollege","abcBranch","username","password")
ArrayList<NameValuePair>dataToSend = new ArrayList<>(); dataToSend.add(new BasicNameValuePair("collegename", college. collegename));
Although I don't know Java, but it should be something like this.
Replace all references of 'College' in the constructor with 'this'.
The 'this' keyword refers to the current object whereas using the class name 'College' directly refers to a static access of a class.

AzureMobileService: Insert data in to table gives exception

I am new to implement Azure Mobile Service. I have refer the demo of ToDoItem given by Azure.
In same manner i have make class User for my own app. Then I am inserting the data in to the MobileServiceTable but it gives me error like below:
{"message":"The operation failed with the following error: 'A null store-generated value was returned for a non-nullable member 'CreatedAt' of type 'CrazyLabApp.Models.User'.'."}
I have not created any field like this as it is not created in ToDoItem demo as well. I have seen that there are 4 fields that are by Default created by the MobileServiceTable. createdAt is one of the field of that.
I am wonder about whats wrong i am doing.
Check my below Userclass:
public class User {
#com.google.gson.annotations.SerializedName("id")
private String ServiceUserId;
#com.google.gson.annotations.SerializedName("email")
private String Email;
#com.google.gson.annotations.SerializedName("firstname")
private String FirstName;
#com.google.gson.annotations.SerializedName("lastname")
private String LastName;
#com.google.gson.annotations.SerializedName("profilepic")
private String ProfilePic;
#com.google.gson.annotations.SerializedName("introduction")
private String Introduction;
#com.google.gson.annotations.SerializedName("website")
private String Website;
#com.google.gson.annotations.SerializedName("title")
private String Title;
#com.google.gson.annotations.SerializedName("_createdAt")
private Date CreatedAt;
#com.google.gson.annotations.SerializedName("coverimage")
private ArrayList<CoverImage> CoverImages;
/*public Date getCreatedAt() {
return CreatedAt;
}
public void setCreatedAt(Date createdAt) {
CreatedAt = createdAt;
}*/
#com.google.gson.annotations.SerializedName("followers")
private ArrayList<User> Followers;
#com.google.gson.annotations.SerializedName("likes")
private ArrayList<Likes> Likes;
#com.google.gson.annotations.SerializedName("collections")
private ArrayList<Collections> Collections;
#com.google.gson.annotations.SerializedName("comments")
private ArrayList<Comments> Comments;
#com.google.gson.annotations.SerializedName("stories")
private ArrayList<Story> Stories ;
//-------------- Methods
public ArrayList<Story> getStories() {
return Stories;
}
public void setStories(ArrayList<Story> stories) {
Stories = stories;
}
public ArrayList<com.promact.crazylab.model.Comments> getComments() {
return Comments;
}
public void setComments(ArrayList<com.promact.crazylab.model.Comments> comments) {
Comments = comments;
}
public ArrayList<com.promact.crazylab.model.Collections> getCollections() {
return Collections;
}
public void setCollections(ArrayList<com.promact.crazylab.model.Collections> collections) {
Collections = collections;
}
public ArrayList<com.promact.crazylab.model.Likes> getLikes() {
return Likes;
}
public void setLikes(ArrayList<com.promact.crazylab.model.Likes> likes) {
Likes = likes;
}
public ArrayList<User> getFollowers() {
return Followers;
}
public void setFollowers(ArrayList<User> followers) {
Followers = followers;
}
public ArrayList<CoverImage> getCoverImages() {
return CoverImages;
}
public void setCoverImages(ArrayList<CoverImage> coverImages) {
CoverImages = coverImages;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getWebsite() {
return Website;
}
public void setWebsite(String website) {
Website = website;
}
public String getIntroduction() {
return Introduction;
}
public void setIntroduction(String introduction) {
Introduction = introduction;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public String getProfilePic() {
return ProfilePic;
}
public void setProfilePic(String profilePic) {
ProfilePic = profilePic;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
FirstName = firstName;
}
public String getServiceUserId() {
return ServiceUserId;
}
public void setServiceUserId(String serviceUserId) {
ServiceUserId = serviceUserId;
}
#Override
public boolean equals(Object o) {
return o instanceof User && ((User) o).ServiceUserId == ServiceUserId;
}
}
Also check below code the way i am inserting it:
final User u = new User();
u.setFirstName(mName);
u.setEmail(mEmail);
u.setProfilePic(mUrl);
mUserTable = mClient.getTable(User.class);
// Insert the new item
new AsyncTask<Void, Void, Void>(){
#Override
protected Void doInBackground(Void... params) {
try {
final User entity = mUserTable.insert(u).get();
} catch (Exception e){
//createAndShowDialog(e, "Error");
System.out.println("Error: "+e.toString());
}
return null;
}
}.execute();
Please help me in this.
The "_createdat" column will be populated automatically by Azure Mobile Services so there is no need to include it in your model. Delete this property from the User class. Its presence is probably overwriting the auto-populated value with a null.
you can solve this problem by just deleting createdAt column from your user table in azure.
Why this error is coming :
I am not sure But I guess this error is coming because createdAt is a non-nullable member and you cannot left it null.
EDIT :
Another aspect of the system columns is that they cannot be sent by the client. For new tables (i.e., those with string ids), if an insert of update request contains a property which starts with ‘__’ (two underscore characters), the request will be rejected. The ‘__createdAt’ property can, however, be set in the server script (although if you really don’t want that column to represent the creation time of the object, you may want to use another column for that) – one way where this (rather bizarre) scenario can be accomplished. If you try to update the ‘__updatedAt’ property, it won’t fail, but by default that column is updated by a SQL trigger, so any updates you make to it will be overridden anyway.
for more info take a look here :-http://blogs.msdn.com/b/carlosfigueira/archive/2013/11/23/new-tables-in-azure-mobile-services-string-id-system-properties-and-optimistic-concurrency.aspx

OpenPojo IncompatibleClassChangeError Exception

I'm using OpenPojo for validating getter and setter methods of a class.
But while trying to validate my getter and setter methods I'm having following exception:
java.lang.IncompatibleClassChangeError: class com.openpojo.reflection.java.bytecode.asm.SubClassCreator has
interface org.objectweb.asm.ClassVisitor as super class
Here is my code:
public final class ClientToken implements RememberMeAuthenticationToken {
private static final long serialVersionUID = 3141878022445836151L;
private final String clientName;
private final Credentials credentials;
private String userId;
private boolean isRememberMe;
public ClientToken(final String clientName, final Credentials credentials) {
this.clientName = clientName;
this.credentials = credentials;
}
public void setUserId(final String userId) {
this.userId = userId;
}
public void setRememberMe(boolean isRememberMe) {
this.isRememberMe = isRememberMe;
}
public String getClientName() {
return this.clientName;
}
public Object getCredentials() {
return this.credentials;
}
public Object getPrincipal() {
return this.userId;
}
#Override
public String toString() {
return CommonHelper.toString(ClientToken.class, "clientName", this.clientName, "credentials", this.credentials,
"userId", this.userId);
}
public boolean isRememberMe() {
return isRememberMe;
}
}
Does anybody help me why this problem occurs.
Have you tried to add the ASM 5.0.3 or higher as a dependency?
It seems an older version for ASM is getting pulled in.

Categories