Android Question Error while trying editing the Date field

Enthousiastic

Active Member
Licensed User
Hello , as the title says an error appear whle editing the Date field. When i click a row in the table
a "window" with details of the specific record appears. When I press the edit button guids me to an activity
(editact ) , in which when I try to edit the date i have the following error :

<< *** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
3
** Activity (main) Pause, UserClosed = true **
** Activity (editact) Create, isFirst = true **
3
** Activity (editact) Resume **
Error occurred on line: 127 (B4XDialog)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:89)
at anywheresoftware.b4a.objects.B4XViewWrapper.getHeight(B4XViewWrapper.java:145)
at b4a.example.b4xdialog$ResumableSub_ShowCustom.resume(b4xdialog.java:1141)
at b4a.example.b4xdialog._showcustom(b4xdialog.java:911)
at b4a.example.b4xdialog$ResumableSub_ShowTemplate.resume(b4xdialog.java:169)
at b4a.example.b4xdialog._showtemplate(b4xdialog.java:126)
at b4a.example.editact$ResumableSub_edRTDate_FocusChanged.resume(editact.java:777)
at b4a.example.editact._edrtdate_focuschanged(editact.java:722)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$1.run(BA.java:352)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Service (starter) Destroy (ignored)** >>


Can you tell me what is wrong ? Many thanks enthousiastic
 

Attachments

  • StartCep.zip
    19.6 KB · Views: 39

Mahares

Expert
Licensed User
Can you tell me what is wrong ? Many thanks enthousiastic
The biggest issue is that you forgot to initialize the DateTemplate:
B4X:
Activity.LoadLayout("frmEdit")
    Base = Activity
    Dialog.Initialize(Base)
    Dialog.Title = " CHANE DATE"
    DateTemplate.Initialize     'this was missing
There are other issues. But, if you figure the rest out, that is great. If not, come back. I am pretty sure I or someone else can produce a working project with your data.
 
Upvote 0

Enthousiastic

Active Member
Licensed User
Τhanks for your answer was crucial !!!!
There are two more questions .
Can you tell me please in above project how : a) When opens the Datepicker I want to indicate the current date taken from the field
database and not today date b) When I update the current record with a new date , this doesn't save it and in the original table
has null value.
 
Upvote 0

Mahares

Expert
Licensed User
When opens the Datepicker I want to indicate the current date taken from the field
database and not today date
I don't think you can do that as the default date is today's date. If you look at the DateTemplate class module in the Xui Views lib, you will see that it uses current date as default.
When I update the current record with a new date , this doesn't save it and in the original table
has null value.
I did make it save the record with the proper date. I think it has to do with the date formats. The database table has date as yyyy-MM-dd, but the B4Xtable has a date format of dd-MM-yyyy. You have to go back and forth between the formats. The reason, you are getting null in the saved date is because you are not probably using the proper format during the save. I can PM you a working project where it it works or post in the forum. Let me know.
 
Upvote 0

Mahares

Expert
Licensed User
I will do some rehearsals changing the date formats .
There is nothing wrong with the way you are doing it by storing the data as yyyy-MM-dd in SQLite and displaying dd-MM-yyyy in B4XTable. It works just fine. You just have to be careful when you are switching from one to the other during display and save. Please note that B4XTable DATE column always expects ticks so it displays the correct visual real date on the table. If you need further help, just holler.
 
Upvote 0

Enthousiastic

Active Member
Licensed User
Hello again , I have good news, I think the problem is solved !!
In Designer I added a label "lblRTdate" not visible behind the edRTdate EditBox.
In the sub Register_click ,, I also added the following lines :
Dim d As Long =DateTime.DateParse(edRTDate.Text)
DateTime.DateFormat = "yyyy-MM-dd"
lblRTDate.Text=DateTime.Date(d)
Log("lblRTDate Text now became to ======> " & lblRTDate.Text)

and in the update query in the arrays object I changed the edRTDate.Text with lblRTDate.Text.

Thank you very much !!!!!!!!!!
 
Upvote 0
Top