Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Firebase Database firebaseDatabase.update() function causes crash
Started by BK PANARA Mar 28 2019 09:53 PM

9 replies to this topic
fireabase database update app crash
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

BK PANARA

[GLOBAL: userInfoPane.html]
BK PANARA
  • Enthusiast

  • 65 posts
  • Corona SDK

Hi @Scott Harrison,

I am using plugin Firebase database and build with latest corona build : 2019.3470
some time firebaseDatabase.update() cause App crash , no crash on every time call. That's strange issue.

I am doing this with my App data:
sample code like my App's data handling with firebase database:

local t1 = {i1 = "index 1",i2 = "index 2"}
local tt = {firstEntry = "Hello World Updated",
                    secondEntry = "second Entry 1",
                    thirdEntry = json.encode(t1),                    
                  }
firebaseDatabase.update("testData",tt,listener)

I can see this error in device log:
 

03-29 11:14:19.358 13232-13232/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mycompany.myapp, PID: 13232
    java.lang.IllegalArgumentException: illegal type
        at com.naef.jnlua.LuaState.lua_setfield(Native Method)
        at com.naef.jnlua.LuaState.setField(Unknown Source:4)
        at com.ansca.corona.CoronaLua.newEvent(CoronaLua.java:119)
        at plugin.firebaseDatabase.LuaLoader$update$1.onComplete(LuaLoader.java:350)
        at com.google.android.gms.internal.firebase_database.zzdh.run(Unknown Source:6)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7529)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

I have tested this same thing with your sample App on github , got same error.
 
Can you please help me what is the issue there ?

Thank you.
Bhavin :)


[TOPIC: post.html]
#2

Scott Harrison

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

  • 1,807 posts
  • Enterprise

I just test out your code need listener is not defined at least in your snippet

local t1 = {i1 = "index 1",i2 = "index 2"}
local tt = {firstEntry = "Hello World Updated",
                    secondEntry = "second Entry 1",
                    thirdEntry = json.encode(t1),                    
                  }
firebaseDatabase.update("testData",tt,function ( e )
          -- do stuff here
        end) 


[TOPIC: post.html]
#3

BK PANARA

[GLOBAL: userInfoPane.html]
BK PANARA
  • Enthusiast

  • 65 posts
  • Corona SDK

Hi @Scott Harrison,

That was just to show you table format i am using.
otherwise everything is defined there. let me show you main.lua of your sample app after i update it.


Strange that App not crashed every time when we call .update() function , but sometime it's crashed.
You can duplicate this issue : try click update button , again and again after you got alert "Data Updated." 

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

local updateButton
updateButton = widget.newButton( {
  x = display.contentCenterX,
  y = display.contentCenterY + 100,
  id = "Update Hello World",
  labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
  label = "Update Hello World",
  onEvent = function ( e )
    if (e.phase == "ended") then
        local t1 = {i1 = "index 1",i2 = "index 2"}
        local tt = {firstEntry = "Hello World Updated",
                    secondEntry = "second Entry 1",
                    thirdEntry = json.encode(t1),                    
                  }
        firebaseDatabase.update("testData", tt , function (ev)
            if(ev.isError) then
                -- native.showAlert( "Could not Upload Data", ev.error , {"Ok"} )
                print("Could not Upload Data")
            else
                native.showAlert( "Data Updated", "" , {"Ok"} )
            end
        end
       )
    end
  end
} )

 



[TOPIC: post.html]
#4

Scott Harrison

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

  • 1,807 posts
  • Enterprise

This has been patched please build in an hour



[TOPIC: post.html]
#5

BK PANARA

[GLOBAL: userInfoPane.html]
BK PANARA
  • Enthusiast

  • 65 posts
  • Corona SDK

Thank you so much @Scott Harrison,
I tested it and no crash so far, i will do more testing and see there is no crash.


 



[TOPIC: post.html]
#6

aiglesiassanz

[GLOBAL: userInfoPane.html]
aiglesiassanz
  • Observer

  • 27 posts
  • Corona SDK

Hi Scott,

firebase Analytics crashes in all my apps since last week.

 

FATAL EXCEPTION: main
                    Pixel 3 XL: Process: com.xxxx.xxxx, PID: 23422
                    Pixel 3 XL: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp;
                    Pixel 3 XL: at plugin.firebaseAnalytics.LuaLoader$init$1.run(LuaLoader.java:166)
                    Pixel 3 XL: at android.os.Handler.handleCallback(Handler.java:873)
                    Pixel 3 XL: at android.os.Handler.dispatchMessage(Handler.java:99)
                    Pixel 3 XL: at android.os.Looper.loop(Looper.java:193)
                    Pixel 3 XL: at android.app.ActivityThread.main(ActivityThread.java:6718)
                    Pixel 3 XL: at java.lang.reflect.Method.invoke(Native Method)
                    Pixel 3 XL: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
                    Pixel 3 XL: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
                    Pixel 3 XL: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.xxxxxx.xxxxxxx-_b5pmWREejOINSrcuz5dBA==/base.apk"],nativeLibraryDirectories=[/data/app/com.xxxxx.xxxx-_b5pmWREejOINSrcuz5dBA==/lib/arm, /data/app/com.xxxx.xxxxxxx-_b5pmWREejOINSrcuz5dBA==/base.apk!/lib/armeabi-v7a, /system/lib]]
                    Pixel 3 XL: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
                    Pixel 3 XL: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                    Pixel 3 XL: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                    Pixel 3 XL: ... 8 more
                    Pixel 3 XL:   Force finishing activity com.xxx.xxxxxx/com.ansca.corona.CoronaActivity


[TOPIC: post.html]
#7

vb66r55

[GLOBAL: userInfoPane.html]
vb66r55
  • Enthusiast

  • 54 posts
  • Corona SDK

Hi Scott.

 

I built with Corona Simulator 2019.3480.

 

But sometimes there will be a "flashback" situation.

 

In addition, I would like to ask, no matter whether I use Set or Update, it will cover the data, I want to use it to make a chat room, what should I do to avoid coverage?

 

local NewData = {} -- My chat data

firebaseDatabase.update("World",{NewData,json.decode( TalkJson )}, function (ev)

 

TalkJson is my past records,but firebase only received NewData after sending.......

 

Thank you.



[TOPIC: post.html]
#8

BK PANARA

[GLOBAL: userInfoPane.html]
BK PANARA
  • Enthusiast

  • 65 posts
  • Corona SDK

Hi @Scott Harrison,

I just got a crash when App start when device has no internet.
 

ERROR: Runtime error
I/Corona  (31800): java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.FirebaseDatabase.getReference(java.lang.String)' on a null object reference
I/Corona  (31800): Java Stack Trace:
I/Corona  (31800): 	plugin.firebaseDatabase.LuaLoader$get.invoke(LuaLoader.java:437)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:220)
I/Corona  (31800): 	com.ansca.corona.Controller.updateRuntimeState(Controller.java:382)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:450)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
I/Corona  (31800): stack traceback:
I/Corona  (31800): 	[C]: in function 'get'
I/Corona  (31800): 	?: in function 'listener'
I/Corona  (31800): 	/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/timer/timer.lua:217: in function 'method'
I/Corona  (31800): 	/Users/jenkins/slaveroot/work
I/Corona  (31800): ERROR: Runtime error
I/Corona  (31800): java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.FirebaseDatabase.getReference(java.lang.String)' on a null object reference
I/Corona  (31800): Java Stack Trace:
I/Corona  (31800): 	plugin.firebaseDatabase.LuaLoader$get.invoke(LuaLoader.java:437)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:220)
I/Corona  (31800): 	com.ansca.corona.Controller.updateRuntimeState(Controller.java:382)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:450)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
I/Corona  (31800): stack traceback:
I/Corona  (31800): 	[C]: ?
I/Corona  (31800): 	[C]: in function 'get'
I/Corona  (31800): 	?: in function 'listener'
I/Corona  (31800): 	/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/timer/timer.lua:217: in function 'method'
I/Corona  (31800): 	/Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:236: in function </Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:205>

Can you please help me to solve this ?

When device has internet , firebase init Successfully , only issue with No internet. 

Thank you.

 



[TOPIC: post.html]
#9

Scott Harrison

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

  • 1,807 posts
  • Enterprise

Hi @Scott Harrison,

I just got a crash when App start when device has no internet.
 

ERROR: Runtime error
I/Corona  (31800): java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.FirebaseDatabase.getReference(java.lang.String)' on a null object reference
I/Corona  (31800): Java Stack Trace:
I/Corona  (31800): 	plugin.firebaseDatabase.LuaLoader$get.invoke(LuaLoader.java:437)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:220)
I/Corona  (31800): 	com.ansca.corona.Controller.updateRuntimeState(Controller.java:382)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:450)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
I/Corona  (31800): stack traceback:
I/Corona  (31800): 	[C]: in function 'get'
I/Corona  (31800): 	?: in function 'listener'
I/Corona  (31800): 	/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/timer/timer.lua:217: in function 'method'
I/Corona  (31800): 	/Users/jenkins/slaveroot/work
I/Corona  (31800): ERROR: Runtime error
I/Corona  (31800): java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.FirebaseDatabase.getReference(java.lang.String)' on a null object reference
I/Corona  (31800): Java Stack Trace:
I/Corona  (31800): 	plugin.firebaseDatabase.LuaLoader$get.invoke(LuaLoader.java:437)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)
I/Corona  (31800): 	com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:220)
I/Corona  (31800): 	com.ansca.corona.Controller.updateRuntimeState(Controller.java:382)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:450)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1625)
I/Corona  (31800): 	com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1380)
I/Corona  (31800): stack traceback:
I/Corona  (31800): 	[C]: ?
I/Corona  (31800): 	[C]: in function 'get'
I/Corona  (31800): 	?: in function 'listener'
I/Corona  (31800): 	/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/timer/timer.lua:217: in function 'method'
I/Corona  (31800): 	/Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:236: in function </Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:205>

Can you please help me to solve this ?

When device has internet , firebase init Successfully , only issue with No internet. 

Thank you.

 

This has been patched please rebuild


  • BK PANARA likes this

[TOPIC: post.html]
#10

BK PANARA

[GLOBAL: userInfoPane.html]
BK PANARA
  • Enthusiast

  • 65 posts
  • Corona SDK

Thanks @Scott Harrison
its fixed :)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: fireabase database, update, app crash