Android Tutorial Any threads just for newbies?

Just getting started with BA4 and am very confused. I don't understand many terms and terminology. Have next to no experience with Java though am reasonably proficient with Basic.

A friend sent me a YouTube link to getting started and that's been helpful. I was able to get the emulator up and running. When I tried "Hello World" again tonight, I now get a Java FileNotfound error (1.bal) in the emulator.

Tried searching the forum but get overwhelmed with results. Are there any threads that just handle getting started newby questions? I tried a bunch of "beginner" & "tutorial" threads but they all seem to quickly evolve into more advanced techniques I am lost before I can even get started.

I'm excited about getting started programming for Android. TIA for any help.

Swede
AOU - Swede's Dock in Lovely Lavallette, NJ - home of Gösta H. Lovgren. Anal Orifi Unwanted
 

JonPM

Well-Known Member
Licensed User
Longtime User
At the top of the site click on documentation, then download the Beginners Guide.
 

Swede

Member
Licensed User
Longtime User
Thanks, Jon, I've done that. And it appears it's gonna be a great help. Am currently printing the first 80 pages. {grin}

But I can't compile the first example. I keep getting "Input string not in a correct format error"

B4X:
 LblComments.Text="Enter the Result" & $CRLF & "Click on OK"

That's the line. LblComments is created exactly as is shown in the docs.

Thx

Here's the whole code:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Btn_Action As Button
   Dim EditText1 As EditText
   Dim LblComments As Label
   Dim lblMathSign As Label
   Dim lblNumber1 As Label
   Dim lblNumber2 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("Main")
  New
  Dim Number1, Number2 As Int
End Sub
Sub New
  Number1 = Rnd(1-10)
  Number2  = Rnd(1-10)
  lblNumber1 = Number1
  lblNumber2 = Number2
  LblComments.Text="Enter the Result" & $CRLF & "Click on OK"
  edt_Result = ""
End Sub
Sub btnAction_Click
  If Btn_Action.Text = "O K" Then
     If edt_Result.Text = "" Then
       Msgbox(" No result Entered", "E R R O R")
      Else Check_Result   
    End If
  End If
End Sub
Sub Check_Result
   If edt_Result.Text = Number1 + Number2 Then
      LblComments.Text = "G O O D Result" & $CRLF & "Click on New"
     Btn_Action = "N E W"
    Else 
     LblComments.Text = "B U M M E R"  & $CRLF & "Enter a new result" & $CRLF & "and Click OK"
   End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Btn_Action_Click
   
End Sub
 
Last edited:

Swede

Member
Licensed User
Longtime User
When you downloaded the Beginner's Guide you also got a folder called SourceCode where you find the source code of all the programs in the Beginner's Guide so you can compare them with yours.

Best regards and good luck.

Thx Klaus. However there is no Source Code folder in the zip I dl'ed.


Yep - another PBer on board!

Are there many of us here? Maybe we should get together and form a support group. {grin}

Swede
 

Swede

Member
Licensed User
Longtime User
Okay, after correcting (several) errors, am now getting am getting
Compiling code. 0.09
Compiling layouts code. 0.02
Generating R file. 0.38
Compiling generated Java code. Error
B4A line: 45
Btn_Action = \
javac 1.6.0_26
src\ba4\my_first_program\main.java:260: inconvertible types
found : java.lang.String
required: android.widget.Button
mostCurrent._btn_action.setObject((android.widget.Button)("N E W"));
error

Code is: Line 45 '<<<<<<<<<<<<<<<<<<<<<<<<<<<

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Btn_Action As Button
   Dim edt_Result As EditText
   Dim LblComments As Label
   Dim lblMathSign As Label
   Dim lblNumber1 As Label
   Dim lblNumber2 As Label
   Dim Number1, Number2 As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("Main")
  New
End Sub
Sub New
  Number1 = Rnd(1, 10)
  Number2  = Rnd(1,10)
  lblNumber1 = Number1
  lblNumber2 = Number2
  LblComments.Text="Enter the Result" & CRLF & "Click on OK"
  edt_Result = ""
End Sub
Sub btnAction_Click
  If Btn_Action.Text = "O K" Then
     If edt_Result.Text = "" Then
       Msgbox(" No result Entered", "E R R O R")
      Else 
       Check_Result   
    End If
  End If
End Sub
Sub Check_Result
   If edt_Result.Text = Number1 + Number2 Then
      LblComments.Text = "G O O D Result" & CRLF & "Click on New"
     Btn_Action = "N E W" '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Else 
     LblComments.Text = "B U M M E R"  & CRLF & "Enter a new result" & CRLF & "and Click OK"
   End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Btn_Action_Click
   
End Sub

Am lost here. Help appreciated.
 

Swede

Member
Licensed User
Longtime User
Thx Klaus. Have the Source code folder now. MyFirstprogram from Source code still gives error
Compiling code. Error
Could not find file 'G:\Basic4android\Documentation\Beginners Guide\SourceCode\MyFirstProgram\Files\mainwithkeyboard.bal'.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Are there many of us here? Maybe we should get together and form a support group. {grin}

Swede

Made the $CRLF mistake myself a few times...constants are a little confusing in having no indicator and sometimes in a class or sometimes not. It doesn't mean the same as it does in PB either since Linux Based they should have just called it LF. The Beginners guide is a big help and makes good toilet reading...especially on a smartphone. I got the other User Guide thing too which is smaller, but goes over more advanced stuff. It took some getting used to, but was easy for me since I've used PowerBASIC and C#/PHP lately. Since it converts to Java the BASIC syntax has a little more object oriented flow and syntax to it.

I kinda like it and how objects can be reused better than PB. I've seen a lot of people here as well as the documentation actually often dimming a variable that isn't needed. Areas like the dimming labels to hold references to the Labels within a Listview instead of just calling the methods of them direct. The one that would need this functionality the most though is Sender, but it is declared as the Base View class so you have to dim a specific view class to hold it. Select Case structures are missing fall through processing with breaks and advanced options like ranges and comma separated lists too. Ctrl+Space will become your friend. I find it easier to use it than scan the documentation or forum.
 

Swede

Member
Licensed User
Longtime User
These lines
B4X:
lblNumber1 = Number1  
lblNumber2 = Number2
edt_Result = ""
must be changed to
B4X:
lblNumber1.Text = Number1  
lblNumber2.Text = Number2
edt_Result.Text = ""
Best regards.

Thx. Here's my (first program code) code:
B4X:
Sub New
  Number1 = Rnd(1, 10)
  Number2  = Rnd(1,10)
  lblNumber1.Text = Number1
  lblNumber2.Text = Number2
  LblComments.Text="Enter the Result" & CRLF & "Click on OK"
  edt_Result.Text = ""
End Sub

And here's error:
Compiling code. 0.00
Compiling layouts code. 0.00
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 45
Btn_Action = \
javac 1.6.0_26
src\ba4\my_first_program\main.java:260: inconvertible types
found : java.lang.String
required: android.widget.Button
mostCurrent._btn_action.setObject((android.widget.Button)("N E W"));
^
1 error

I have no idea what I'm doing wrong.

Thx

I will try the sample MyFirst program now.
 

Swede

Member
Licensed User
Longtime User
Made the $CRLF mistake myself a few times...constants are a little confusing in having no indicator and sometimes in a class or sometimes not. It doesn't mean the same as it does in PB either since Linux Based they should have just called it LF. The Beginners guide is a big help and makes good toilet reading...especially on a smartphone. I got the other User Guide thing too which is smaller, but goes over more advanced stuff. It took some getting used to, but was easy for me since I've used PowerBASIC and C#/PHP lately. Since it converts to Java the BASIC syntax has a little more object oriented flow and syntax to it.
Glad to see a familiar face. {grin} My problem is I have NO C experience. No PHP exper either. {sigh} Basic is all I know (and not that very well it appears.)
I kinda like it and how objects can be reused better than PB. I've seen a lot of people here as well as the documentation actually often dimming a variable that isn't needed. Areas like the dimming labels to hold references to the Labels within a Listview instead of just calling the methods of them direct. The one that would need this functionality the most though is Sender, but it is declared as the Base View class so you have to dim a specific view class to hold it. Select Case structures are missing fall through processing with breaks and advanced options like ranges and comma separated lists too.
That's ALL way ahead of me yet. Just confusing to me at this stage. Am a compleat Newbie remember {smile}
Ctrl+Space will become your friend. I find it easier to use it than scan the documentation or forum.
Thanks, Roger, I'll start to use it.
 

klaus

Expert
Licensed User
Longtime User
What line is line 45 ?

It would be easier to help you if you posted the whole project as a zip file (IDE menu Files / Export As Zip)
so we see what you have done and how. Too often the error is not where you think it is but somewhere else.

Best regards.
 
Top