Ihave this error :Attempt to invoke virtual method 'void com.hbb20.CountryCodePicker.registerCarrierNumberEditText(android.widget.EditText)' on a null object reference
package com.example.geolab;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;
import com.hbb20.CountryCodePicker;
public class PhoneLoginActivity extends AppCompatActivity {
private CountryCodePicker ccp;
private EditText userPhoneNumber;
private Button cuntiniueToVerify;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
InitializeFields();
cuntiniueToVerify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Intent OTPintent = new Intent(PhoneLoginActivity.this,OTPActivity.class);
OTPintent.putExtra("mobile",ccp.getFullNumberWithPlus().replace(" ",""));
startActivity(OTPintent);
}
});
}
private void InitializeFields()
{
userPhoneNumber = (EditText) findViewById(R.id.phone_number_id);
ccp = (CountryCodePicker) findViewById(R.id.ccp);
ccp.registerCarrierNumberEditText(userPhoneNumber);
cuntiniueToVerify = (Button) findViewById(R.id.cuntiniue_button);
}
}
//------------------------------------------------------layout-------------------------------------------
<RelativeLayout 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" tools:context=".PhoneLoginActivity">
<com.hbb20.CountryCodePicker
android:id="@+id/ccp"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="250dp"
app:ccp_defaultNameCode="IR" />
<EditText
android:id="@+id/phone_number_id"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginLeft="165dp"
android:layout_marginTop="250dp"
android:ems="10"
android:hint="Mobile Number"
android:inputType="textPersonName"
android:singleLine="true"
android:text="9121111111"
/>
<Button
android:id="@+id/cuntiniue_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_below="@+id/phone_number_id"
android:layout_marginLeft="100dp"
android:layout_marginTop="30dp"
android:layout_marginRight="100dp"
android:text="Cuntiniue"
android:textAllCaps="false"
android:textSize="24sp"
android:textColor="@color/white"
android:background="@drawable/rounded_button"
/>
In onCreate, I don't see a method where you set layout for activity.
On Sun, Aug 22, 2021 at 05:48 Arsenic1379 @.***> wrote:
package com.example.geolab;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;
import com.hbb20.CountryCodePicker;
public class PhoneLoginActivity extends AppCompatActivity {
private CountryCodePicker ccp; private EditText userPhoneNumber; private Button cuntiniueToVerify; @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); InitializeFields(); cuntiniueToVerify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent OTPintent = new Intent(PhoneLoginActivity.this,OTPActivity.class); OTPintent.putExtra("mobile",ccp.getFullNumberWithPlus().replace(" ","")); startActivity(OTPintent); } });}
private void InitializeFields() { userPhoneNumber = (EditText) findViewById(R.id.phone_number_id); ccp = (CountryCodePicker) findViewById(R.id.ccp); ccp.registerCarrierNumberEditText(userPhoneNumber); cuntiniueToVerify = (Button) findViewById(R.id.cuntiniue_button); }
}
//------------------------------------------------------layout-------------------------------------------
<com.hbb20.CountryCodePicker android:id="@+id/ccp" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_marginLeft="25dp" android:layout_marginTop="250dp" app:ccp_defaultNameCode="IR" />
<EditText android:id="@+id/phone_number_id" android:layout_width="220dp" android:layout_height="wrap_content" android:layout_marginLeft="165dp" android:layout_marginTop="250dp" android:ems="10" android:hint="Mobile Number" android:inputType="textPersonName" android:singleLine="true" android:text="9121111111"
/><Button android:id="@+id/cuntiniue_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="4dp" android:layout_below="@+id/phone_number_id" android:layout_marginLeft="100dp" android:layout_marginTop="30dp" android:layout_marginRight="100dp" android:text="Cuntiniue" android:textAllCaps="false" android:textSize="24sp" @./white" @./rounded_button" />
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hbb20/CountryCodePickerProject/issues/502, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFQ32D7C56FJQC3PMOR7D3T6DW3JANCNFSM5CS5OQ2Q .