I am building a Chatting App and I am stuck at Sign Up because when I run my application, it shows a blank screen.
By the way, I am using binding.
And when I use this code:
public class SignUpActivity extends AppCompatActivity {
ActivitySignUpBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivitySignUpBinding.inflate(getLayoutInflater());
binding.getRoot();
}
}
It shows a blank screen.
And when I use this code:
public class SignUpActivity extends AppCompatActivity {
ActivitySignUpBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
}
}
It shows an error that: NewAge Chat keeps stopping.
activity_sign_up.xml code:
<?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"
tools:context=".SignUpActivity"
android:orientation="vertical"
android:background="@drawable/w1"
android:gravity="center">
<ImageView
android:layout_height="100dp"
android:layout_width="100dp"
android:id="@ id/logo"
android:src="@drawable/ic_launcher_favicon"/>
<EditText
android:id="@ id/txtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:textColor="@color/white"
android:textColorHint="@color/chatbackground"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:ems="10"
android:inputType="textPersonName"
android:padding="9dp"
android:textSize="20sp"/>
<EditText
android:id="@ id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:textColor="@color/white"
android:textColorHint="@color/chatbackground"
android:layout_marginBottom="10dp"
android:ems="10"
android:inputType="textEmailAddress"
android:padding="9dp"
android:textSize="20sp"/>
<EditText
android:id="@ id/txtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textColor="@color/white"
android:textColorHint="@color/chatbackground"
android:layout_marginBottom="10dp"
android:ems="10"
android:inputType="textPassword"
android:padding="9dp"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@ id/alreadyHaveAccount"
android:layout_gravity="right"
android:text="Already Have An Account"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="18sp"/>
<Button
android:layout_width="150dp"
android:layout_height="70dp"
android:text="Sign Up"
android:textSize="20sp"
android:textAllCaps="false"
android:id="@ id/btnSignUp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:layout_width="170dp"
android:layout_height="70dp"
android:id="@ id/btnGoogle"
android:text="Google"
android:textAllCaps="false"
android:backgroundTint="@color/white"
android:textColor="@color/black"
android:textSize="20sp"
android:paddingTop="5dp"
android:paddingBottom="7dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginRight="40sp"/>
<Button
android:layout_width="170dp"
android:layout_height="70dp"
android:id="@ id/btnFacebook"
android:text="Facebook"
android:textAllCaps="false"
android:backgroundTint="@color/fb_color"
android:textColor="@color/black"
android:textSize="20sp"
android:paddingTop="5dp"
android:paddingBottom="7dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@ id/signUpPhone"
android:text="Sign Up with Phone"
android:textSize="25sp"
android:textColor="@color/white"
android:paddingTop="25dp"
android:textStyle="bold"/>
</LinearLayout>
SignUpActivity.java code:
package com.agrim.newagechat;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.agrim.newagechat.databinding.ActivitySignUpBinding;
public class SignUpActivity extends AppCompatActivity {
ActivitySignUpBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivitySignUpBinding.inflate(getLayoutInflater());
binding.getRoot();
getSupportActionBar().hide();
binding.alreadyHaveAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SignUpActivity.this, SignInActivity.class);
startActivity(intent);
}
});
}
}
AndroidManifest.xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.agrim.newagechat">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/ic_launcher_favicon"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_launcher_favicon"
android:supportsRtl="true"
android:theme="@style/Theme.NewAgeChat"
tools:targetApi="31">
<activity
android:name=".SignUpActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="false"/>
</application>
</manifest>
I have setted the <intent-filter></intent-filter>
also...
CodePudding user response:
hare your SignUpActivity you forgot to set ContentView. that's why your screen is blank. You need to do something like this
public class SignUpActivity extends AppCompatActivity {
ActivitySignUpBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivitySignUpBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
}
}