Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Unable to fetch Array from firebase db using plugin.firebaseDatabase
Started by assif_tiger Dec 18 2017 10:00 AM

22 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

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 :

{
  "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 Sample Code:

 
   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)

 

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)


[TOPIC: post.html]
#2

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

This has been patched

[TOPIC: post.html]
#3

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

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.

 

 

Attached Files



[TOPIC: post.html]
#4

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

try now



[TOPIC: post.html]
#5

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

Same RuntimeError



[TOPIC: post.html]
#6

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

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



[TOPIC: post.html]
#7

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

Hi Scott,

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

 

Appreciate your instant reply & kind gesture.

 

Merry Christmas & Happy New Year

Thanks,

Assif



[TOPIC: post.html]
#8

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

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

 

Json Data on Firebase DB :

 

 
{
  "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
}
 
 

 

 

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)


[TOPIC: post.html]
#9

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

This has been patched



[TOPIC: post.html]
#10

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

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

 

{
  "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 Sample Code:

 


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)

 

 

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



[TOPIC: post.html]
#11

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

This is patched

[TOPIC: post.html]
#12

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

Thanks, Scott.



[TOPIC: post.html]
#13

bluedeskstudios

[GLOBAL: userInfoPane.html]
bluedeskstudios
  • Observer

  • 15 posts
  • Corona SDK

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
} )


[TOPIC: post.html]
#14

bluedeskstudios

[GLOBAL: userInfoPane.html]
bluedeskstudios
  • Observer

  • 15 posts
  • Corona SDK

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)



[TOPIC: post.html]
#15

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

What corona version are you using?

[TOPIC: post.html]
#16

bluedeskstudios

[GLOBAL: userInfoPane.html]
bluedeskstudios
  • Observer

  • 15 posts
  • Corona SDK

I am using Corona Version 2017.3135



[TOPIC: post.html]
#17

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

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



[TOPIC: post.html]
#18

assif_tiger

[GLOBAL: userInfoPane.html]
assif_tiger
  • Contributor

  • 166 posts
  • Corona SDK

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

 

- Assif



[TOPIC: post.html]
#19

bluedeskstudios

[GLOBAL: userInfoPane.html]
bluedeskstudios
  • Observer

  • 15 posts
  • Corona SDK

It worked! Thanks Scott!



[TOPIC: post.html]
#20

iammorjj

[GLOBAL: userInfoPane.html]
iammorjj
  • Observer

  • 2 posts
  • Corona SDK

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

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



[TOPIC: post.html]
#21

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

Corona updated there libraries again so I have to update this plugin as well



[TOPIC: post.html]
#22

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,796 posts
  • Enterprise

This has been patched please rebuild

[TOPIC: post.html]
#23

iammorjj

[GLOBAL: userInfoPane.html]
iammorjj
  • Observer

  • 2 posts
  • Corona SDK

Thank you, Scott!




[topic_controls]
[/topic_controls]