Back

Query.select throwing NullPointerException

  • 0
  • Android
Chirag_doosra
21 Jul, 2024, 10:38

This is my code to fetch data for a particular Attribute-

TypeScript
try {
  lifecycleScope.launch {
    val getData = databases.getDocument(
      databaseId = "669...49",
      collectionId = "669...15d6",
      documentId = "669...2f5b",
      queries = listOf(Query.select(listOf("PrescriptionFileId")))
    )
    Log.d("GetFilesLog", "Result: ${getData}")
  }
catch (e : Exception){
  Log.d("GetFilesLog", "Exception: $e")
}```

Here is the Exception -

FATAL EXCEPTION: OkHttp Dispatcher (Ask Gemini) Process: com.geekster.getfilesfromdevice, PID: 29680 java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String at io.appwrite.models.Document$Companion.from(Document.kt:89) at io.appwrite.services.Databases$getDocument$converter$1.invoke(Databases.kt:190) at io.appwrite.services.Databases$getDocument$converter$1.invoke(Databases.kt:188) at io.appwrite.Client$awaitResponse$2$1.onResponse(Client.kt:541) at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:545) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012)```

Even though I'm finally able to get the required data from the Attribute by getting the response without the query and converting the response to Json and then to Gson and then getting the required data. But I wanted to know is there any issue with my codebase or the query isn't working for Android SDK. I've tried using other queries, few of them work as expected but other ones throw some errors.

TL;DR
Developers are facing a NullPointerException when using Query.select in Android SDK for fetching data. The issue lies in the conversion process. To resolve it, the developers can obtain the response without the query, convert it to JSON and then to Gson format, and extract the required data from there. The error might be related to the codebase or the query itself not working effectively with Android SDK.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more