Android Question App exit when I clicked a button to go to other Activity

Luis Felipe

Member
Licensed User
Longtime User
Hello everybody,

I got 2 activities and I pass from 1 to another with a button.
But when I clicked it the app exit.
I can't see the log because I debug the app directly on the Tablet and it's not USB debugging compatible :-(.
The code stops here:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        SQL1.Close        'if the user closes the program we close the database
    End If
End Sub
I haven't change nothing to the code (related to the sqlite db) modified by Klaus...

Thanx in advance.
 

Attachments

  • SurveyTravel9.zip
    21.3 KB · Views: 74

Luis Felipe

Member
Licensed User
Longtime User
You don't need to close explicitly close SQL.

Why don't you use B4A-Bridge to debug your app?
I use the code they adviced me ;-).
I use B4A Bridge and it's a huge help to see it working on the tablet.
The problem is that I can't see the log in B4A : may be it's why the tablet is not USB Debugging compatible...
Thanx Erel, I'm going to modify the code...
 
Upvote 0

Luis Felipe

Member
Licensed User
Longtime User
You are doing it while your app is running, right?
Doing it in the Emulator I got that log:
B4X:
LogCat connected to: emulator-5554
Copying updated assets files (3)


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


0


** Activity (main) Pause, UserClosed = false **


Error occurred on line: 93 (main)
java.lang.RuntimeException: Object should first be initialized (Label).


    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
    at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at b4a.latbus.encuestaviajeros.initializeGlobals(encuestaviajeros.java:282)
    at b4a.latbus.encuestaviajeros.afterFirstLayout(encuestaviajeros.java:95)
    at b4a.latbus.encuestaviajeros.access$100(encuestaviajeros.java:16)
    at b4a.latbus.encuestaviajeros$WaitForLayout.run(encuestaviajeros.java:76)


    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (encuestaviajeros) Create, isFirst = true **
 
Upvote 0

Luis Felipe

Member
Licensed User
Longtime User
Go to line 93 and check why the label was not initialized.

Hi,
I'm stucked since yesterday and I don't understand why it doesn't work.
If I use
B4X:
LblNumEnc.Initialize("")
I got an error message telling me that this field has been generated by The Designer so I don't have to initiliaze it.
If I don't put that code I got this error message:
B4X:
java.lang.RuntimeException: Object should first be initialized (Label).


Did you forget to call Activity.LoadLayout?
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
    at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at b4a.latbus.main.initializeGlobals(main.java:282)
    at b4a.latbus.main.afterFirstLayout(main.java:95)
    at b4a.latbus.main.access$100(main.java:16)
    at b4a.latbus.main$WaitForLayout.run(main.java:76)


    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **

Of course I do an "Activity.LoadLayout("MenuPrincipal")" in the Sub Activity_Create...

This message comes from the Emulator (since I can't see the log in B4A and as I can't change the device because the tablet I got is the only device where the app is going to run).
Thank you for your help...
 

Attachments

  • SurveyTravel10.zip
    21.3 KB · Views: 80
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is this line:
Dim LblNumEnc As Label : LblNumEnc.Text = ""
You MUST not try to set view properties in Globals !!!
Only Dim LblNumEnc As Label
You had a similar line in EncuestaViajeros Globals !
The same for these lines in EncuestaViajeros Globals
B4X:
If Main.gCodigoBus = True Then
    edtCodigoBus.Text = Main.gCodigoBus
End If
I moved these to Activity_Resume, depending on what you need you can move them to Activity:Create.

Suggestions:
1) I wouldn't put the VALIDAR button in EncuestaViajeros at the bottom of the ScrollView panel but at the bottom of the screen.
If the user scrolls up to change something he needs to scroll down to see the button.

2) In EncuestaViajeros in Sub btnValidar1_Click you have these lines at the end.
B4X:
Main.NewSurvey = True
StartActivity("Main")
And in Main in Activity_Resume these:
B4X:
If NewSurvey = True Then
    StartActivity("EncuestaViajeros")
    NewSurvey = False
End If
You quit and you come back ?
You can remove these lines.

3) You still have a wrong layout variant for ScrollViewLayout !?
In this layout evrerything is limitedet to a 600dip width, why don't you use the whole width ?

Attached a modified version.
 

Attachments

  • SurveyTravel10_1.zip
    21.4 KB · Views: 72
Upvote 0

Luis Felipe

Member
Licensed User
Longtime User
The problem is this line:
Dim LblNumEnc As Label : LblNumEnc.Text = ""
You MUST not try to set view properties in Globals !!!
Only Dim LblNumEnc As Label
You had a similar line in EncuestaViajeros Globals !
The same for these lines in EncuestaViajeros Globals
B4X:
If Main.gCodigoBus = True Then
    edtCodigoBus.Text = Main.gCodigoBus
End If
I moved these to Activity_Resume, depending on what you need you can move them to Activity:Create.

Suggestions:
1) I wouldn't put the VALIDAR button in EncuestaViajeros at the bottom of the ScrollView panel but at the bottom of the screen.
If the user scrolls up to change something he needs to scroll down to see the button.

2) In EncuestaViajeros in Sub btnValidar1_Click you have these lines at the end.
B4X:
Main.NewSurvey = True
StartActivity("Main")
And in Main in Activity_Resume these:
B4X:
If NewSurvey = True Then
    StartActivity("EncuestaViajeros")
    NewSurvey = False
End If
You quit and you come back ?
You can remove these lines.

3) You still have a wrong layout variant for ScrollViewLayout !?
In this layout evrerything is limitedet to a 600dip width, why don't you use the whole width ?

Attached a modified version.

Merci Klaus.
Done the modifications, the app launch but exit when I click the Button to go to the second screen with the same error :
B4X:
** Activity (main) Pause, UserClosed = false **


Error occurred on line: 96 (main)
java.lang.RuntimeException: Object should first be initialized (Label).


    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
    at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at b4a.latbus.encuestaviajeros.initializeGlobals(encuestaviajeros.java:282)
    at b4a.latbus.encuestaviajeros.afterFirstLayout(encuestaviajeros.java:95)
    at b4a.latbus.encuestaviajeros.access$100(encuestaviajeros.java:16)
    at b4a.latbus.encuestaviajeros$WaitForLayout.run(encuestaviajeros.java:76)


    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (encuestaviajeros) Create, isFirst = true **

1) That's a good idea, I'm going to see how to do it.

2) The idea is that when you've filled your first survey and click "Validate", you come back to the same screen with all fields blank but the 4 first that I kept into Globals Variables (related to the person (who is the same for the entire) doing the survey to the clients, so it's done to make it quicker).
So I've put all the edittext and radiobutton to .text="" and .checked, but when it's done I don't know Where to go to simulate that the page is reloading (like a webpage) : so I think to go back to the first screen, do a test and then comeback to the second screen.
If you want to go to the first screen (by example if you want to select another type of survey (that are to come)) you click the "Menu" button a the top of the screen. That's why I do a test with the GloBal variable "NewSurvey"...

3) Mi mistake : I modified it yesterday but I did not set it as default. Thank you.
 

Attachments

  • SurveyTravel11.zip
    21.4 KB · Views: 65
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Did you use the project I sent you ?
This one works, so if yours doesn't means that you didn't use it or you didn't do all modifications !
To let you get some experience you should try on your own to find out the problem.
With the explanations in my previous post you should get it.
 
Upvote 0

Luis Felipe

Member
Licensed User
Longtime User
Did you use the project I sent you ?
This one works, so if yours doesn't means that you didn't use it or you didn't do all modifications !
To let you get some experience you should try on your own to find out the problem.
With the explanations in my previous post you should get it.

I downloaded it, print it and then reviewed it line by line to see the differences and modified my code...
The only thing I haven't done so far is to use only your file.
Thank you Klaus.

[Update]: I tried your file and I got the same problem... I don't know where is the problem if you say that it's working for you. :-(
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, I can't help you for this.
I downloaded back the project from post #13 !!!
In your project in post #14 in the code in EncuestaViajeros you have this line:
Dim lblPonFecha As Label : lblPonFecha.Text = ""
Find the error !?

So I don't know what you are doing.
 
Upvote 0

Luis Felipe

Member
Licensed User
Longtime User
Sorry, I can't help you for this.
I downloaded back the project from post #13 !!!
In your project in post #14 in the code in EncuestaViajeros you have this line:
Dim lblPonFecha As Label : lblPonFecha.Text = ""
Find the error !?

So I don't know what you are doing.

You did it right Klaus.
I just copy/paste the whole project and now it woks.
But the only thing is that my Global variables declared in Sub Process_Globals in Main are not kept when I go back to the second screen...
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but you really need to look at the basics of programming !
It seems you don't understand what you are doing !

In Main you declare:
B4X:
Dim gCodigoBus As String
In EncuestaViajeros in Activity_Resume you have this:
B4X:
If Main.gCodigoBus = True Then
    edtCodigoBus.Text = Main.gCodigoBus
End If
Up to you to find what's wrong !
 
Upvote 0

Luis Felipe

Member
Licensed User
Longtime User
Sorry, but you really need to look at the basics of programming !
It seems you don't understand what you are doing !

In Main you declare:
B4X:
Dim gCodigoBus As String
In EncuestaViajeros in Activity_Resume you have this:
B4X:
If Main.gCodigoBus = True Then
    edtCodigoBus.Text = Main.gCodigoBus
End If
Up to you to find what's wrong !

Well I thought I had declared a global variable in the Main module.
Then I test if I kept a value in it after I clicked the Validate button.
If it's the case I pass it to the edittext field in my second screen in order to have one field already filled.
Where am I wrong ?
That part is working now. I got to see how to clear my global variables when needed. I keep testing...
Thanx.
 
Upvote 0
Top