Android Question This error is driving me nuts!

Discussion in 'Android Questions' started by Troberg, Apr 20, 2015.

  1. Troberg

    Troberg Well-Known Member Licensed User

    Something's wrong. It might be me who has messed up (and probably is), but I have a suspicion that, just this once, it just might be Erel :).

    Error log:

    The error occurs in this sub:

    Code:
    Sub MsgSend(From As Object, Recipient As Object, Msg As String, Args As cArgPackage) AsInt
      IfSubExists(Recipient, 
    "MsgRecieved"Then
        
    Dim ThisMsg As cMsg
        ThisMsg.Initialize(From, Msg, Args)
        LogMsg(Msg,
    False)
        ReturnCallSub2(Recipient, 
    "MsgRecieved", ThisMsg) '<-- Error on this line
      Else
        Logs.LogError(
    "Listener didn't answer:" & Recipient & " (" & Msg & ")")
        ListenerUnRegister(Recipient)
        
    Return -1
      EndIf
    End Sub
    Well, here's the kicker: There is not a double involved anywhere in this. All arguments are checked, and have their proper values and are properly initialized.

    Now, things get really strange: If I cut it down to a minimalistic example, it works. All the code which runs is the same, I just cut out a few thousand lines that are not even involved.

    It gets even better. I've encountered the exact same problem in completely different code in another program, but there, I can't replicate it on my devices. In this case, there isn't even a double variable declared anywhere in the entire project.

    See the attached file for the code. There's quite a lot of code in there, and most of it is not tested yet (I don't think I've ever done so much code without a test run before...), but it runs until the error happens. Just start the app and it will error within a second or so.

    Anyone who can tell me what to do to fix this will have a serious bug fixing IOU from me. I'll really dig into any problem where I might help you. This issue is really driving me nuts.
     

    Attached Files:

    thedesolatesoul likes this.
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Code:
    Return CallSub2(Recipient, "MsgRecieved", ThisMsg) '<-- Error on this line
    The problem is that CallSub2 always returns a String. In your case it is returning null from MsgReceived sub (I dont know why).
    But as the return parameter is Int, this is cast to an Int (through Double).

    So I guess the issue is why MsgReceived returns "null".
     
    NJDude and Troberg like this.
  3. thedesolatesoul

    thedesolatesoul Expert Licensed User

    You do have some classes that dont return anything, those are probably returning null. Add a Return 0 or something to see if it fixes the issue.
     
    NJDude, Peter Simpson and Troberg like this.
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

    So looking through your project, I like how you partioning your project gearing up for a pretty large project. You must be missing a view where you can see and hide all your modules in the IDE.
    cMsgHub is the most interesting, its like an EventBus. Listeners get attach and can send and receive messages to class instances that are registered and alive.
    The slight issue with this is the risk of having a memory leak if you do not detach the listeners.
    The other issue is if the listener is inactive, like a service or activity (or any singleton inactive object), what would CallSub return?
    Also I think the check for Listener doesnt exist should also check not only for subexist (which is static), but also for if the object exists or is active? Or it just fails to respond?
    Anyway I am only commenting because I think this is very very cool.
     
  5. Troberg

    Troberg Well-Known Member Licensed User

    The thing is, if I set a breakpoint in MsgRecieved, I can see that it's never called. So, the call fails, not the return.

    Yep, still lots of stubs, but not when this bit is concerned.
     
  6. Troberg

    Troberg Well-Known Member Licensed User

    Thanks!

    As you say, I'm building the foundation for a big project. I've been hinting about a community project for a while, this is the foundation for that. I'm doing a lot of work to facilitate stuff like:

    * Modularization. Parts should be pretty isolated, even though they have to coexist. Code for a part should be, as far as possible, in a separate module.
    * Separation of concern. Each part should handle one thing, and nothing else.
    * Providing a good framwork for common functionality.

    If you are curious, I've written a lot on the project here (on architecture, on project management and on ideas to include): http://troberg.synology.me/wikidash/pmwiki.php . Use any name for username, dashguest for password.

    The idea is to make a complete solution for an in-car system, preferably an Android based car computer (like these: http://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20150420042317&SearchText=android car computer ) or simply a tablet or phone.

    I've realized a long time ago that I can't be the expert on everything, and I don't have the capacity or time to make it all by myself. However, I can create a platform, and then other people can build parts on which they are experts, and I can build parts which I'm an expert on. All in all, we would have great fun and the potential to corner a fresh market together.
     
    thedesolatesoul and eurojam like this.
  7. thedesolatesoul

    thedesolatesoul Expert Licensed User

    So doesnt that mean when CallSub2 fails (maybe it cannot find Recipient instance), it will return null and that would cause a cast error?

    From the docs of CallSub:
    so you need to handle this case i.e.
    Dim retCallSub as String = CallSub(...)
    If retCallSub <> "" then Return retCallSub
     
    Peter Simpson, NJDude and Troberg like this.
  8. Troberg

    Troberg Well-Known Member Licensed User

    Don't think that's the problem either. The they all run in the same activity, and should not be paused, and only a few lines before the call, I test it with SubExists(Recipient, "MsgRecieved").
     
  9. Troberg

    Troberg Well-Known Member Licensed User

    Just to make it clear how it should work (and does work in a small example...), here's a minimalistic project where it does work.
     

    Attached Files:

  10. Troberg

    Troberg Well-Known Member Licensed User

    Missed this: Not a very big risk. As soon as I try to call a listener and it doesn't answer, I drop it. Since broadcasts will be pretty frequent, that won't take long.
     
    thedesolatesoul likes this.
  11. Troberg

    Troberg Well-Known Member Licensed User

    You are onto something here. When I add this line just before the call:

    Log(CallSub2(Recipient, "MsgRecieved", ThisMsg))

    it logs a null. The breakpoint in MsgRecieved is not reached, so it's not something inside MsgRecieved, it's something that goes wrong with CallSub. Yet, SubExists(Recipient, "MsgRecieved") returns true, so things are not all messed up, it does find the correct sub.

    So, what happens to make it miss the call?
     
  12. Troberg

    Troberg Well-Known Member Licensed User

    Added a Log(IsPaused(Recipient)) just before the call. It returns True.

    So, how can the main activity be paused when called from an object that's declared in the very same activity (and, in a single activity app...)??? And, if it's paused, how do I un-pause it?
     
  13. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Wow, that is some impressive documentation. I just got lost in there for a while, it would take me ages to write that.

    I dont think its paused. What you passed to it was the class instance 'Me', not the activity instance 'Activity'.
    This requires more thinking.
     
    Peter Simpson and NJDude like this.
  14. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Ok, I got it to work. You cannot send the message in Activity_Create and that is when the activity is still paused. You have to do it after Activity_Resume.
     
  15. Troberg

    Troberg Well-Known Member Licensed User

    Ah, it was that easy (once figured out)!

    Thanks, I'm very grateful, and I hope I can some day fix such a nasty problem for you.
     
    thedesolatesoul likes this.
  16. Peter Simpson

    Peter Simpson Expert Licensed User

  17. Troberg

    Troberg Well-Known Member Licensed User

    To be quite honest, I usually don't either. However, I was away from my dev computer for a while, and wanted to get started. So, what to do besides documenting and designing?
     
    thedesolatesoul likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice