Android Question Empty strings from EditText

KOSTAS KOUSINOVALIS

Member
Licensed User
Hello
I have 3 EditTexts and a Button
When i press the Button i check the texts in EditTexts and only in the 3d EditText there is text
The others are empty
The only difference between them is that the 3rd is Multline
This strange thing happens only in one activity, all the others are working fine

This is the code

Username=EditText1.text
Password=EditText2.text
Email=EditText3.text
 

Dwight J

New Member
Licensed User
Hello
I have 3 EditTexts and a Button
When i press the Button i check the texts in EditTexts and only in the 3d EditText there is text
The others are empty
The only difference between them is that the 3rd is Multline
This strange thing happens only in one activity, all the others are working fine

This is the code

Username=EditText1.text
Password=EditText2.text
Email=EditText3.text
Did you register all of them in the design view with Create Dim?? Im just new to this, but seems like a possibility.
 

mangojack

Well-Known Member
Licensed User
Are you manually filling the Edittexts yourself ... or via code ?

The above 'code' really tells us nothing .

Are you able to upload your project File > Export As Zip. Or at least a trimmed version displaying the problem.
 

KOSTAS KOUSINOVALIS

Member
Licensed User
I am sending the project
The problem is in the "Logged" Activity
Maybe if someone of have also a suggetion on how to read the data from the web response in a better way :)
 

Attachments

mangojack

Well-Known Member
Licensed User
I have tried with two layouts .. "smsLogin" (2 EditTexts) & "single" (3 EditTexts)

In both layouts, inputting 'Username' & 'Password' shows correctly in Logs.
All I get is returned Job string "ERR 001 - Invalid Username" ... which does not suprise me.


B4X:
Sub Button1_Click   '.... Log In Button
    Dim job1 As HttpJob
    Username=EditText1.Text
    Password=EditText2.Text
 
    Log(Username)     'Log Output was Correct
    Log(Password)     'Log Output was Correct
 
    job1.Initialize("Job1", Me)
    job1.Download2("http://www.lexiconsoftware.gr/sms/service.asmx/Balance" , Array As String("username",EditText1.Text,"password",EditText2.Text))
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Log(Job.GetString)    ' =  <string xmlns="http://www.lexiconsoftware.gr/">ERR 001 - Invalid username </string>
       '.......................................

In this test app there is no need for OKHttp lib.
Also .. maybe have a read here .https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/#content
 
Last edited:

mc73

Well-Known Member
Licensed User
Hello Kostas, just two notes, irrelevant to your initial question but I think they will be of use:

1) I wouldn't recommend the download method, but probably you've used it for testing reasons.

2) Search for the "wait for" feature. It will make your requests easier to handle. For e.g. your log-in request sub could be:

B4X:
Sub Button1_Click
   Username=EditText1.Text.Trim
   Password=EditText2.Text.Trim
   Private errorMessage As String
   Private job As HttpJob
   job.Initialize("", Me)
   job.PostString("http://www.lexiconsoftware.gr/sms/service.asmx/Balance",$"username=${Username}&password=${Password}"$)
   wait for (job) JobDone (job As HttpJob)
   If job.Success Then
       Dim s As String
       s = job.GetString
       Private startIndexSearch As String=$"<string xmlns="http://www.lexiconsoftware.gr/">"$
       Private startIndex As Int=s.IndexOf(startIndexSearch)
       If startIndex>-1 Then
           startIndex=startIndex+startIndexSearch.Length
           Private endIndex As Int=s.IndexOf2("</string>",startIndex)
           If endIndex>startIndex Then
               s=s.substring2(startIndex,endIndex)
               If s.Contains("ERR") Then
                   errorMessage=s
               End If
           Else
               errorMessage="Parse error"
           End If
       Else
           errorMessage="Parse error"
       End If
   Else
       errorMessage="Error: "&job.ErrorMessage
   End If
   job.Release
   If errorMessage.Length>0 Then
       Label3.Text=errorMessage
   Else
       Label3.Text ="Υπόλοιπο " & s
       StartActivity("logged")
   End If
End Sub
 
Top