Android Question Object should first be initialized (EditText).

Nickle

Member
Licensed User
Longtime User
Hi There,

I keep getting this Error. I know I have not done something right but cant figure it out. My Intention is to get the field values from EditText and based on values purpose validation. I am using XmlLayoutBuilder for the first time.

java.lang.RuntimeException: Object should first be initialized (EditText).

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ButtonLogin As Button
    Dim btnLinkToRegisterScreen As Button
    Dim vdsLogo As ImageView
    Dim vMobile As EditText
    Dim vPassword As EditText
    Dim First As String
    Dim Second As String

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Dim x As XmlLayoutBuilder
    x.LoadXmlLayout(Activity, "activity_login")
    Dim tc As Int = 0xffffffff 'the format is AARRGGBB
    Activity.Color = tc
    vdsLogo = x.GetView("vdsLogo")
    ButtonLogin = x.GetView("button1")
    vMobile.Initialize("")
    vMobile = x.GetView("txtmobile")
    vPassword = x.GetView("txtpassword")
End Sub

Sub ButtonLogin_Click
    First = vMobile.Text
    Msgbox(vMobile.Text, "")
End Sub
 

Nickle

Member
Licensed User
Longtime User
I get same error even If I initial both EditText fields

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Dim x As XmlLayoutBuilder
    x.LoadXmlLayout(Activity, "activity_login")
    Dim tc As Int = 0xffffffff 'the format is AARRGGBB
    Activity.Color = tc
    vdsLogo = x.GetView("vdsLogo")
    ButtonLogin = x.GetView("button1")
    vMobile.Initialize("")
    vMobile = x.GetView("txtmobile")
    vPassword.Initialize("")
    vPassword = x.GetView("txtpassword")
End Sub

Sub ButtonLogin_Click
    First = vMobile.Text
    Msgbox(vMobile.Text, "")
    'StartActivity("Test")
End Sub
 
Upvote 0

Nickle

Member
Licensed User
Longtime User
B4X:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.mobilesolutionsgh.voucherdistrutionsysterm.activity.MainActivity">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_marginBottom="15dp"
        android:src="@drawable/mobilesolutionsghlogo" />

    <EditText
        android:id="@+id/mobile"
        android:layout_width="350dp"
        android:layout_height="60dp"
        android:layout_marginTop="25dp"
        android:background="@color/colorPrimary"
        android:drawableLeft="@mipmap/ic_email"
        android:drawableStart="@mipmap/ic_email"
        android:hint="User"
        android:inputType="number"
        android:padding="14dp"
        android:textColor="#ffff"
        android:textColorHint="#ffff"
        android:textSize="20sp"
        android:tag="txtmobile" />

    <EditText
        android:id="@+id/password"
        android:layout_width="350dp"
        android:layout_height="60dp"
        android:layout_marginTop="30dp"
        android:background="@color/colorPrimary"
        android:drawableLeft="@mipmap/ic_lock"
        android:drawableStart="@mipmap/ic_lock"
        android:hint="Password"
        android:inputType="textPassword"
        android:padding="14dp"
        android:textColor="#ffff"
        android:textColorHint="#ffff"
        android:textSize="20sp"
        android:tag="txtpassword" />

    <Button
        android:id="@+id/btnLogin"
        android:layout_width="250dp"
        android:layout_height="60dp"
        android:layout_marginTop="70dp"
        android:background="@drawable/button_background"
        android:text="Sign IN"
        android:textStyle="bold"
        android:tag="ButtonLogin"/>

    <Button
        android:id="@+id/btnLinkToRegisterScreen"
        android:layout_width="250dp"
        android:layout_height="60dp"
        android:layout_marginTop="15dp"
        android:background="@drawable/button_background"
        android:text="Register"
        android:textStyle="bold" />

</LinearLayout>
 
Upvote 0
Top