I have designed a login page using Viewpager(login page and register page) and set a fragment to load on that ViewPager when using intend for login button to go the next page after login it crashes
note:I have simply made login button to intent to next page even there is nothing in username and password just to test everything works fine
Here is my Java coding:
public class LoginFragment extends Fragment{
View view;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
final Button b = null;
b.findViewById(R.id.Loginbutton);
final EditText e = getView().findViewById(R.id.user);
EditText e1 = getView().findViewById(R.id.pass);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent l = new Intent(getActivity(), AfterLogin.class);
startActivity(l);
}
});
view = inflater.inflate(R.layout.fragment_login,container,false);
return view;
}
public LoginFragment() {}
}
There is no error but during runtime it makes the app crash...
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/DefaultWhite">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="125dp"
android:text="@string/app_name"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp" />
<ImageView
android:contentDescription="@string/LoginText"
android:id="@+id/imageView4"
android:layout_width="48dp"
android:layout_height="57dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="78dp"
app:srcCompat="@drawable/accountbox" />
<EditText
android:id="@+id/user"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="@string/LoginText"
android:gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="300dp"
android:layout_marginRight="20dp"
android:background="@drawable/loginpageloginedittext"
/>
<EditText
android:id="@+id/pass"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="@string/PasswordText"
android:gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginTop="360sp"
android:background="@drawable/loginpageedittextpassword"
android:layout_marginStart="20dp"
android:inputType="textPassword"
/>
<Button
android:id="@+id/LoginButton"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="450dp"
android:background="@drawable/loginbutton"
android:layout_marginStart="20dp"
android:textColor="@color/DefaultWhite"
android:layout_marginEnd="20dp"
android:text="@string/LoginButton" />
<Button
android:id="@+id/registerbutton"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:background="@drawable/forgotpasswordbutton"
android:layout_marginTop="450dp"
android:layout_marginStart="215dp"
android:layout_marginBottom="10dp"
android:text="@string/ForgotPassword" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="600dp"
android:layout_marginStart="160dp"
android:hint="@string/KnowUsMore" />
</android.widget.RelativeLayout>