Solution 1 :
You forgot to set setContentView()
You should set like this:
setContentView(binding.getRoot());
This should work perfectly.
Solution 2 :
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());
}
}
Problem :
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…
Comments
Comment posted by Agrim Singh
Can you also tell me why it says NewAge Chat keeps stopping when I set: setContentView(R.layout.activity_sign_up)
Comment posted by Abdullah Jubayer
maybe you do something wrong in your theme.xml or any other file. can you share the logcat?
Comment posted by Agrim Singh
I have changed this:
Comment posted by Abdullah Jubayer
it’s look like ok. please share your crush log