This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am using dataSnapshot to get a value from my Firebase Database, but I keep getting a null reference error. The path to my firebase is correct and I have Datasnapshot defined, so I am not too sure why this error is coming up.
Here is the snippit that is giving me issues
User user = new User();
String username;
username = (String) datasnapshot.child("Users").child(uid).child("userName").getValue();
user.setusername(username);
navuserName.setText(username);
and this is the error that it is giving me.
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DataSnapshot com.google.firebase.database.DataSnapshot.child(java.lang.String)' on a null object reference
I have Datasnapshot dataSnapshot; defined in the class but the error is being thrown. Any suggestions?
Your variable dataSnapshot is not initialized. It's value is null. You need to initialize the variable before you can use it's methods.
Related
enter image description hereI am trying to persist a value in my table using an update sql statement but i got this error : " execute() is called on closed connection" .. Someone knows how to fix it ?
This question already has answers here:
No results returned by the Query error in PostgreSQL
(6 answers)
Closed 2 years ago.
I'm trying to change the password of the non-admin user in PostgreSQL using jdbc connection.
statement.executeQuery("ALTER ROLE user1 WITH PASSWORD '6789'");
This above query is throwing:
org.postgresql.util.PSQLException: No results were returned by the query
How to resolve this issue?
statement.executeQuery() expects a resultset and you don't get one. Use statement.execute() for an ALTER-statement to avoid this issue.
Link to the manual: https://jdbc.postgresql.org/documentation/head/ddl.html
This question already has answers here:
Getting "ORA-03115: unsupported network datatype or representation" error while fetching array of varchar from anonymous pl/sql
(2 answers)
Closed 3 years ago.
I have a PL/SQL function that returns a "TYPE varr IS VARRAY(100001) OF VARCHAR2(32000);". Using a callable statement for the function, I want to get this vector into a String[] in Java. How should I do it?
I have tried the following code, but it gives an error:
"Exception in thread "main" java.sql.SQLException: ORA-03115: unsupported network datatype or representation".
CallableStatement statement=Database.getConnection().prepareCall("{? = call data_mining.return_treshold}");
statement.registerOutParameter(1, java.sql.Types.ARRAY);
statement.executeQuery();
Array arr=statement.getArray(1);
String[] vec=(String[])arr.getArray();
Add the name of the type in the call to registerOutParameter:
statement.registerOutParameter(1, java.sql.Types.ARRAY, "VARR");
This question already has answers here:
Android Firebase retrieve data from child node
(5 answers)
Closed 4 years ago.
I am building an app that will be able to let you answer assessment questions. Now I have a problem on how to save the scores to the current user. I cannot access the child node. This is the real time database. How can I access the child node under Users
You can simply use for loop to access the users just write this code under addOnEventListener:
DataSnapshot Users = datasnapshot.child("Users");
for(DataSnapshot userChild : Users.getChildren()){
DataSnapshot email = userChild.child("email");
String emailString = email.getValue(String.class);
}
I need to retrieve a double value from a database, which could potentially be stored as null, so I need to detect whether or not it is null before or after retrieving it. However, the method getDouble("columnName") actually returns 0 if the value in the database is null.
I have tried the solutions provided here to no avail (Android Studio says it's unable to resolve wasNull() and getObject():
How do I in JDBC read a possibly null double value from resultSet?
Here is what I've tried so far:
beer.setRating(beerObj.getDouble("myRating"));
if(beerObj.wasNull()){ //'Cannot resolve method wasNull'
}
And this:
Double doubleVal = (Double)beerObj.getObject("myRating"); //'Cannot resolve method getObject()'
I have other properties that I am retrieving using getString("otherColumnName") and that is retrieved properly so I assumed that the beerObj was retrieved properly as well.
Is there another way to check if the double value is null in the database before retrieving it?
Yes put it in your where clause: "WHERE columnname is not null". If there is a record returned then it isn't null if there isn't a record returned then it is null.
Try if (resultset.getObject("columnName") == null). It's hard to tell from your original post if you were trying to use getObject() without passing in a value.