Android Question Error loading SwitchView

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Can you tell me why the AddView statement is making my app display an error that says "Unfortunately, ... has stopped.

There is no other message indicating why.

B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: My Sound Settings
#VersionCode: 1
#VersionName:
#SupportedOrientations: Portrait
#CanInstallToExternalStorage: False
#End Region

'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

    Dim swMasterVolume As SwitchView
    Dim panelMain As Panel
    Dim etMyText As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Main")

    etMyText.Initialize("TextBox")
    etMyText.Text = "Hello"

    panelMain.AddView(etMyText, 0dip, 0dip, 100dip, 50dip)

    swMasterVolume.Initialize(Me, "swMasterVolume")

    'panelMain.AddView(swMasterVolume.Switch, 10dip, 100dip, 200dip, 50dip)

    If StateManager.RestoreState(Activity, "Main", 60) = False Then
    EndIf
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

    StateManager.SaveState(Activity, "Main")
    StateManager.SaveSettings
End Sub

Sub Button1_Click

    Activity.Finish
End Sub

panelMain is a panel view that I added using the designer.

The EditText is displayed and also something unexpected shows up in the EditText. Instead of saying "Hello" it says "True". Not sure why that happens as well. Looks like it is being forced to be a boolean.
 
Last edited:

rleiman

Well-Known Member
Licensed User
Longtime User
is the button part of your layout? If yes then you should NOT initialize the button

Hi Don,

No, it's not in the layout but I tried it both ways. I tried with defining it in the layout and not having the dim statement and the way which you see in my post with the same error.

I also think it has something to do with my layout file because running the sample SwitchView app that comes in the zip file is ok.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
upload your project as zip and we can have a look,....
Sorry for the delay in getting back to you.

I tried to upload the project and the B4A server can't handle a file that large.

I will upload it to my 4shared.com account and post the link so you can download it.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I think I will copy the SwitchView example app and copy and paste parts of my app onto it since the SwitchView sample app displays the SwitchView. At least I know that it works and I will watch to see what coding or views I have in my app that's making a clash.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…