Unable to fetch Array from firebase db using plugin.firebaseDatabase

Hi scott,

I am using the firebaseDatabase plugin & I am able to fetch the data from DB unless I add the array in DB.
please refer the below screenshot.

I tried but the apk getting crash in runtime.

Json**  Data on Firebase DB :**

[lua]

{

  “menu” : {

    “answer” : “4”,

    “categories” : “science”,

    “city” : “New York”,

    “lala” : “tiger”,

    “name” : “John”,

    “option01” : “1”,

    “option02” : “2”,

    “option03” : “3”,

    “option04” : “4”,

    “questions” : “Earth”,

    “results” : [ {

      “quiz” : “sci”

    }, {

      “quiz” : “math”

    }, {

      “quiz” : “gk”

    } ]

  }

}

[/lua]

Lua Sample Code:

[lua]

   firebaseDatabase.get(“menu”, function (ev)

        if(ev.isError) then

            native.showAlert( “Could not Get Data”, ev.error , {“Ok”} )

        else

           native.showAlert( “Data received”, json.encode( ev.data ) , {“Ok”} )

        end

      end)

[/lua]

APK crash Log:

12-18 17:08:21.197 6703-6703/? E/AndroidRuntime: FATAL EXCEPTION: main

                                                 Process: com.bizzcodestudios.gksuccess, PID: 6703

                                                 com.naef.jnlua.LuaRuntimeException: attempt to index a function value

                                                     at com.naef.jnlua.LuaState.lua_setfield(Native Method)

                                                     at com.naef.jnlua.LuaState.setField(Unknown Source)

                                                     at plugin.firebaseDatabase.LuaLoader$get$1.onDataChange(LuaLoader.java:532)

                                                     at com.google.firebase.database.Query$1.onDataChange(Unknown Source)

                                                     at com.google.android.gms.internal.zzajp.zza(Unknown Source)

                                                     at com.google.android.gms.internal.zzakp.zzcxi(Unknown Source)

                                                     at com.google.android.gms.internal.zzaks$1.run(Unknown Source)

                                                     at android.os.Handler.handleCallback(Handler.java:815)

                                                     at android.os.Handler.dispatchMessage(Handler.java:104)

                                                     at android.os.Looper.loop(Looper.java:218)

                                                     at android.app.ActivityThread.main(ActivityThread.java:5657)

                                                     at java.lang.reflect.Method.invoke(Native Method)

                                                     at java.lang.reflect.Method.invoke(Method.java:372)

                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990)

                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785)

This has been patched

Hi scott,

I have re-build the apk & try the same.

But this time got a runtime error as the apk gets open.

PFA Screen.

try now

Same RuntimeError

I clear out the old apps on my phone and rebuild twice, it seems to be working now for me.

Hi Scott,

Thanks a lot.
The plugin is working perfectly now :slight_smile:

Appreciate your instant reply & kind gesture.

Merry Christmas & Happy New Year

Thanks,

Assif

Hello Scott,
I am getting an error for the below valid JSON on firebase again:

Json**  Data on Firebase DB :**

[lua]

{

  “results” : [ {

    “answer” : 4,

    “categories” : “science”,

    “option01” : 1,

    “option02” : 2,

    “option03” : 3,

    “option04” : 4,

    “questions” : “Earth”

  }, {

    “answer” : 5,

    “categories” : “math”,

    “option01” : 2,

    “option02” : 5,

    “option03” : 7,

    “option04” : 3,

    “questions” : 123456,

    “quiz” : “math”

  }, {

    “answer” : “land”,

    “categories” : “science”,

    “option01” : “air”,

    “option02” : “water”,

    “option03” : “land”,

    “option04” : “volcano”,

    “questions” : “Ground”,

    “quiz” : “gk”

  } ],

  “version” : 1

}

[/lua]

APK crash Log:

12-18 17:08:21.197 6703-6703/? E/AndroidRuntime: FATAL EXCEPTION: main

                                                 Process: com.bizzcodestudios.gksuccess, PID: 6703

                                                 com.naef.jnlua.LuaRuntimeException: attempt to index a function value

                                                     at com.naef.jnlua.LuaState.lua_setfield(Native Method)

                                                     at com.naef.jnlua.LuaState.setField(Unknown Source)

                                                     at plugin.firebaseDatabase.LuaLoader$get$1.onDataChange(LuaLoader.java:532)

                                                     at com.google.firebase.database.Query$1.onDataChange(Unknown Source)

                                                     at com.google.android.gms.internal.zzajp.zza(Unknown Source)

                                                     at com.google.android.gms.internal.zzakp.zzcxi(Unknown Source)

                                                     at com.google.android.gms.internal.zzaks$1.run(Unknown Source)

                                                     at android.os.Handler.handleCallback(Handler.java:815)

                                                     at android.os.Handler.dispatchMessage(Handler.java:104)

                                                     at android.os.Looper.loop(Looper.java:218)

                                                     at android.app.ActivityThread.main(ActivityThread.java:5657)

                                                     at java.lang.reflect.Method.invoke(Native Method)

                                                     at java.lang.reflect.Method.invoke(Method.java:372)

                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990)

                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785)

This has been patched

Hi scott,
I placed incorrect json by mistake.
I am trying for below json structure & I am getting null

[lua]

{

  “data”:{

  “results” : [ {

    “answer” : 4,

    “categories” : “science”,

    “option01” : 1,

    “option02” : 2,

    “option03” : 3,

    “option04” : 4,

    “questions” : “Earth”

  }, {

    “answer” : 5,

    “categories” : “math”,

    “option01” : 2,

    “option02” : 5,

    “option03” : 7,

    “option04” : 3,

    “questions” : 123456,

    “quiz” : “math”

  }, {

    “answer” : “land”,

    “categories” : “science”,

    “option01” : “air”,

    “option02” : “water”,

    “option03” : “land”,

    “option04” : “volcano”,

    “questions” : “Ground”,

    “quiz” : “gk”

  } ],

  “version” : 1

}

}

[/lua]

Lua Sample Code:

[lua]

firebaseDatabase.get(“data”, function (ev)

if(ev.isError) then

native.showAlert( “Could not Get Data”, ev.error , {“Ok”} )

else

native.showAlert( “Data received”, json.encode( ev.data ) , {“Ok”} )

end

end)

[/lua]

I want to fetch both the result array & version in one call from firebase.

This is patched

Thanks, Scott.

I am getting a similar error but it seems the problem is the firebase.init() function. After building the sample app you provided on Github, moving it to my android device, and opening the built app it on my android device, I got this error. It should be noted that I used the json file and plist files from my own firebase project, as the ones you provided was empty. I replaced the package name in the json file with the one from the build window. I don’t know what the problem is.
 
Here is the main.lua file
 

local firebaseDatabase = require "plugin.firebaseDatabase" firebaseDatabase.init()   local widget = require("widget") local json = require("json") local bg = display.newRect( display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight ) bg:setFillColor( 1,.5,0 )   local title = display.newText( {text = "Firebase Database", fontSize = 30} ) title.width, title.height = 300, 168 title.x, title.y = display.contentCenterX, 168\*.5 title:setFillColor(1,0,0)   local getButton getButton = widget.newButton( {   x = display.contentCenterX,   y = display.contentCenterY-100,   id = "Get Test Data",   labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },   label = "Get Test Data",   onEvent = function ( e )     if (e.phase == "ended") then       firebaseDatabase.get("testData", function (ev)         if(ev.isError) then             native.showAlert( "Could not Get Data", ev.error , {"Ok"} )         else             native.showAlert( "Data received", json.encode( ev.data ) , {"Ok"} )         end       end)     end   end } ) local setButton setButton = widget.newButton( {   x = display.contentCenterX,   y = display.contentCenterY,   id = "Set Hello World",   labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },   label = "Set Hello World",   onEvent = function ( e )     if (e.phase == "ended") then         firebaseDatabase.set("testData",{firstEntry = "Hello World"}, function (ev)             if(ev.isError) then                 native.showAlert( "Could not Upload Data", ev.error , {"Ok"} )             else                 native.showAlert( "Data send", "" , {"Ok"} )             end         end        )     end   end } )

the runtime error is as follows:

main.lua:2: java.lang.NoSuchMethodError:

No virtual method zzbnw()z

in class Lcom/google

/firebase/FirebaseApp; or its

super classes (declaration of

‘com.google.firebase.FirebaseApp’

appears in /data/app/com.gmail.bluedeskstudios.firebaseDatabase_demo_master-1/base.apk:classes2.dex)

What corona version are you using?

I am using Corona Version 2017.3135

Try a newer verison, I am able to build with Corona-3189

I am using the plugin with Latest corona build & its working perfect.

  • Assif

It worked! Thanks Scott!

Hi, Scott! Same error zzbnw()z. Corona v2018.3326 https://ibb.co/hvbPVe <- pic