Back
Query issue when getting the document from the database in android java
- 1
- Android
- Databases
- Cloud

I get an error when i try to get document from the database and use query to select only 1 column.
Error:
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String
Code:
TypeScript
List<String> queries = new ArrayList<>();
queries.add(Query.Companion.select(Collections.singletonList("topics")));
try {
databases.getDocument(
BuildConfig.APPWRITE_DATABASE_ID,
BuildConfig.APPWRITE_PROFILE_ID,
documentId,
new CoroutineCallback<>((document, error) -> {
if (error != null) {
error.printStackTrace();
return;
}
if (document == null) {
Toast.makeText(context, "Failed to get topics!", Toast.LENGTH_SHORT).show();
return;
}
Log.d("Appwrite", document.toString());
})
);
} catch (AppwriteException e) {
Log.e("Appwrite", e.getMessage());
}
TL;DR
Issue: NullPointerException when trying to get a document from the database and query for one column in Android Java.
Solution: The error is caused by the document being null. Add a null check before using the document to avoid the NullPointerException.
Recommended threads
- update_documents is called inside a func...
Traceback (most recent call last): File "/usr/local/server/src/function/src/main.py", line 23, in main result = databases.update_documents( File "/usr/l...
- Many-to-One RelationShip fields just fil...
Since upgrading to the latest Appwrite Cloud release, the relationships in my collections have stopped working. I have a Many-to-One relation between Request...
- PDO-Sql or Mysql connect from outside da...
Hi, i'm new user in Appwrite. wanna ask about Functions. i using runtime php 8.3. Try make php code to fetch data from outside database using PDO-sql and Mysql ...
