androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout - java

When I click Update Faculty (MaterialCardView) in the activity_main.xml the activity activity_update_faculty.xml suppose to display but my app crashes and closes, I tried to find the problem in the logcat and it says "androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout" I'm struggling to find the problem since I'm still new. Can someone help me, please
Here's is the activity_main.xml :
<?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:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="#+id/addNotice"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="135dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_green"
android:padding="15dp"
android:src="#drawable/ic_notice" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Upload Notice"
android:textColor="#color/textColor"
android:textStyle="bold" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/addGalleryImage"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_purple"
android:padding="15dp"
android:src="#drawable/ic_gallery"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Upload Image"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="#+id/addEbook"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_pink"
android:padding="15dp"
android:src="#drawable/ic_upload"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Upload Ebook"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/faculty"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_yellow"
android:padding="15dp"
android:src="#drawable/ic_group"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Update Faculty"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="#+id/deleteNotice"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/cicle_red"
android:padding="15dp"
android:src="#drawable/ic_delete"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Delete Notice"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</LinearLayout>
Here is the MainActivity.java :
package com.example.adminuniversityapp;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.example.adminuniversityapp.facculty.UpdateFaculty;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
CardView uploadNptice, addGalleryImage, addEbook, faculty;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uploadNptice = findViewById(R.id.addNotice);
addGalleryImage = findViewById(R.id.addGalleryImage);
addEbook = findViewById(R.id.addEbook);
faculty = findViewById(R.id.faculty);
uploadNptice.setOnClickListener(this);
addGalleryImage.setOnClickListener(this);
addEbook.setOnClickListener(this);
faculty.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Intent intent;
switch (v.getId()){
case R.id.addNotice:
intent = new Intent( MainActivity.this,UploadNotice.class);
startActivity(intent);
break;
case R.id.addGalleryImage:
intent = new Intent( MainActivity.this,UploadImage.class);
startActivity(intent);
break;
case R.id.addEbook:
intent = new Intent( MainActivity.this,UploadPdfActivity.class);
startActivity(intent);
break;
case R.id.faculty:
intent = new Intent( MainActivity.this, UpdateFaculty.class);
startActivity(intent);
break;
}
}
}
activity_update_faculty.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".facculty.UpdateFaculty">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
style="#style/Widget.Design.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/ic_add"
app:elevation="3dp"
app:fabSize="normal"/>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Computer Science"
android:textColor="#color/textColor"
android:textSize="22sp"
android:textStyle="bold"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="8dp"
android:background="#c1c1c1"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/csDepartment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/csNoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/no_data_found"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Mechanical Engineering"
android:textColor="#color/textColor"
android:textSize="22sp"
android:textStyle="bold"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="8dp"
android:background="#c1c1c1"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/mechanicalDepartment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/mechNoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/no_data_found"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Physics Department"
android:textColor="#color/textColor"
android:textSize="22sp"
android:textStyle="bold"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="8dp"
android:background="#c1c1c1"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/physicsDepatment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/physicsNoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/no_data_found"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Chemistry Department"
android:textColor="#color/textColor"
android:textSize="22sp"
android:textStyle="bold"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="8dp"
android:background="#c1c1c1"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/chemistryDepatment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/chemistryNoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/no_data_found"/>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
**UpdateFaculty.java:
**
package com.example.adminuniversityapp.facculty;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.example.adminuniversityapp.R; // i had to import this from the other package in order for R.layout works
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class UpdateFaculty extends AppCompatActivity {
FloatingActionButton fab;
private RecyclerView csDepartment, mechanicalDepartment, physicalDepartment, chemistryDepartment;
private LinearLayout csNoData, mechNoData, physicsNoData, chemistryNoData;
private List<TeacherData> list, list2, list3, list4;
private TeacherAdapter adapter;
private DatabaseReference reference, dbRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_faculty);
csDepartment = findViewById(R.id.csDepartment);
mechanicalDepartment = findViewById(R.id.mechanicalDepartment);
physicalDepartment = findViewById(R.id.physicsDepatment);
chemistryDepartment = findViewById(R.id.chemistryDepatment);
csNoData = findViewById(R.id.csDepartment);
mechNoData = findViewById(R.id.mechNoData);
physicsNoData = findViewById(R.id.physicsNoData);
chemistryNoData = findViewById(R.id.chemistryNoData);
reference = FirebaseDatabase.getInstance().getReference().child("teacher");
csDepartment();
mechanicalDepartment();
physicalDepartment();
chemistryDepartment();
fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(UpdateFaculty.this, addTeacher.class));
}
});
}
private void csDepartment() {
dbRef = reference.child("Computer Science");
dbRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
list = new ArrayList<>();
if(!dataSnapshot.exists()){
csNoData.setVisibility(View.VISIBLE);
csDepartment.setVisibility(View.GONE);
} else {
csNoData.setVisibility(View.GONE);
csDepartment.setVisibility(View.VISIBLE);
for (DataSnapshot snapshot: dataSnapshot.getChildren()){
TeacherData data = snapshot.getValue(TeacherData.class);
list.add(data);
}
csDepartment.setHasFixedSize(true);
csDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
adapter = new TeacherAdapter(list, UpdateFaculty.this);
csDepartment.setAdapter(adapter);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void mechanicalDepartment() {
dbRef = reference.child("Mechanical");
dbRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
list2 = new ArrayList<>();
if(!dataSnapshot.exists()){
mechNoData.setVisibility(View.VISIBLE);
mechanicalDepartment.setVisibility(View.GONE);
} else {
mechNoData.setVisibility(View.GONE);
mechanicalDepartment.setVisibility(View.VISIBLE);
for (DataSnapshot snapshot: dataSnapshot.getChildren()){
TeacherData data = snapshot.getValue(TeacherData.class);
list2.add(data);
}
mechanicalDepartment.setHasFixedSize(true);
mechanicalDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
adapter = new TeacherAdapter(list2, UpdateFaculty.this);
mechanicalDepartment.setAdapter(adapter);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void physicalDepartment() {
dbRef = reference.child("Physics");
dbRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
list3 = new ArrayList<>();
if(!dataSnapshot.exists()){
physicsNoData.setVisibility(View.VISIBLE);
physicalDepartment.setVisibility(View.GONE);
} else {
physicsNoData.setVisibility(View.GONE);
physicalDepartment.setVisibility(View.VISIBLE);
for (DataSnapshot snapshot: dataSnapshot.getChildren()){
TeacherData data = snapshot.getValue(TeacherData.class);
list3.add(data);
}
physicalDepartment.setHasFixedSize(true);
physicalDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
adapter = new TeacherAdapter(list3, UpdateFaculty.this);
physicalDepartment.setAdapter(adapter);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void chemistryDepartment() {
dbRef = reference.child("Chemistry");
dbRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
list4 = new ArrayList<>();
if(!dataSnapshot.exists()){
chemistryNoData.setVisibility(View.VISIBLE);
chemistryDepartment.setVisibility(View.GONE);
} else {
chemistryNoData.setVisibility(View.GONE);
chemistryDepartment.setVisibility(View.VISIBLE);
for (DataSnapshot snapshot: dataSnapshot.getChildren()){
TeacherData data = snapshot.getValue(TeacherData.class);
list4.add(data);
}
chemistryDepartment.setHasFixedSize(true);
chemistryDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
adapter = new TeacherAdapter(list4, UpdateFaculty.this);
chemistryDepartment.setAdapter(adapter);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
Here is what it shows on the logcat right after I click the Update Faculty MaterialCardView :
2022-03-22 14:09:03.319 24645-24645/com.example.adminuniversityapp I/Timeline: Timeline: Activity_launch_request time:36107995
2022-03-22 14:09:03.344 24645-24702/com.example.adminuniversityapp V/FA: Recording user engagement, ms: 49869
2022-03-22 14:09:03.367 24645-24702/com.example.adminuniversityapp V/FA: Connecting to remote service
2022-03-22 14:09:03.369 24645-24671/com.example.adminuniversityapp V/FA: onActivityCreated
2022-03-22 14:09:03.373 24645-24702/com.example.adminuniversityapp V/FA: Connection attempt already in progress
2022-03-22 14:09:03.373 24645-24702/com.example.adminuniversityapp V/FA: Activity paused, time: 61111997
2022-03-22 14:09:03.375 24645-24645/com.example.adminuniversityapp D/DecorView[]: getWindowModeFromSystem windowmode is 1
2022-03-22 14:09:03.409 24645-24645/com.example.adminuniversityapp E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-03-22 14:09:03.409 24645-24645/com.example.adminuniversityapp I/FloatingActionButton: Setting a custom background is not supported.
2022-03-22 14:09:03.411 24645-24645/com.example.adminuniversityapp E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-03-22 14:09:03.468 24645-24645/com.example.adminuniversityapp E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-03-22 14:09:03.509 24645-24645/com.example.adminuniversityapp D/AndroidRuntime: Shutting down VM
2022-03-22 14:09:03.513 24645-24645/com.example.adminuniversityapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.adminuniversityapp, PID: 24645
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.adminuniversityapp/com.example.adminuniversityapp.facculty.UpdateFaculty}: java.lang.ClassCastException: androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3580)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3752)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2191)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8049)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Caused by: java.lang.ClassCastException: androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout
at com.example.adminuniversityapp.facculty.UpdateFaculty.onCreate(UpdateFaculty.java:46)

csNoData = findViewById(R.id.csDepartment);
This is where the exception occurs. The reason is that the view with id csDepartment is a RecyclerView not a LinearLayout. Because of that, itcannot be cast to aLinearLayout`.
To solve it, replace that line of code with this:
csNoData = findViewById(R.id.csNoData);

Related

JavaNullPointerException after Login

Hi, so I'm developing my first app on android studio and I have a problem with my dashboard after I logged in I keep getting Java nullpointerexception. I somehow managed to make it work yesterday but it broked after I tried logging in with another user than the one I used and also it was showing the username of the old user that was logged in.
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.licentabuna, PID: 2405
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.licentabuna/com.example.licentabuna.MainFrame}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' on a null object reference
at com.example.licentabuna.MainFrame.onCreate(MainFrame.java:32)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
Interface code:
package com.example.licentabuna;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class MainFrame extends AppCompatActivity implements View.OnClickListener{
private FirebaseAuth firebaseAuth;
TextView firebasenameview;
Button toast;
private CardView addPacienti,searchPacienti,transfPacienti,checkPacienti;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_frame);
firebasenameview = findViewById(R.id.firebase_nume);
firebaseAuth=FirebaseAuth.getInstance();
final FirebaseUser user=firebaseAuth.getCurrentUser();
String finaluser=(user).getEmail();
String result=finaluser.substring(0,finaluser.indexOf("#"));
String resultemail=result.replace(".","");
firebasenameview.setText("" + resultemail);
/* toast.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainFrame.this,users.getEmail(),Toast.LENGTH_SHORT).show();
}
});*/
addPacienti=(CardView)findViewById(R.id.add_pacient);
searchPacienti=(CardView)findViewById(R.id.cautare_pacient);
transfPacienti=(CardView)findViewById(R.id.transf_pacient);
addPacienti.setOnClickListener(this);
searchPacienti.setOnClickListener(this);
transfPacienti.setOnClickListener(this);
}
#Override
public void onClick(View view){
Intent i;
switch (view.getId()){
case R.id.add_pacient:i=new Intent(this,addPacienti.class);
startActivity(i);
break;
case R.id.cautare_pacient:i=new Intent(this,cautarePacienti.class);
startActivity(i);
break;
// case R.id.transf_pacient:i=new Intent(this,transfPacientiActivity.class);
// startActivity(i);
// break;
default:break;
}
}
}
Login code:
package com.example.licentabuna;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class Login extends AppCompatActivity {
private EditText mID;
private EditText mPassword;
private Button mloginBtn;
private FirebaseAuth fAuth;
private ProgressBar progressBar;
int counter=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mID = (EditText) findViewById(R.id.ID);
mPassword = (EditText) findViewById(R.id.Pw);
mloginBtn = (Button) findViewById(R.id.loginBtn);
mloginBtn.setOnClickListener(v -> {userLogin();});
progressBar = (ProgressBar) findViewById(R.id.progressBar);
fAuth=FirebaseAuth.getInstance();
mloginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.loginBtn:
startActivity(new Intent(Login.this,MainFrame.class));
userLogin();
}
}
});
}
private void userLogin() {
String id = mID.getText().toString().trim();
String pass = mPassword.getText().toString().trim();
if (TextUtils.isEmpty(id)) {
mID.setError("Adaugati emailul dvs");
mID.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(id).matches()) {
mID.setError("Adauga-ti o adresa valida de email");
mID.requestFocus();
return;
}
if (TextUtils.isEmpty(pass)) {
mPassword.setError("Adaugati parola");
mPassword.requestFocus();
return;
}
if (pass.length() < 6) {
mPassword.setError("Parola trebuia sa aiba 6 sau mai multe caractere");
mPassword.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
fAuth.signInWithEmailAndPassword(id,pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user.isEmailVerified()){
startActivity(new Intent(Login.this,MainFrame.class));
}else{
user.sendEmailVerification();
Toast.makeText(Login.this,"Verifica-ti emailul pentru verificare",Toast.LENGTH_LONG).show();
}
if(task.isSuccessful()){
//redirect spre profil user
Toast.makeText(Login.this, "Login Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Login.this, MainFrame.class));
}else{
Toast.makeText(Login.this,"Verifica-ti-va datele de autentificare",Toast.LENGTH_LONG).show();
}
}
});
}
};
XML:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:background="#drawable/background1"
tools:context=".MainFrame">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="#+id/firebase_nume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="137dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="197dp"
android:layout_marginBottom="21dp"
android:fontFamily="#font/roboto"
android:text="Salut,"
android:textColor="#020202"
android:textSize="25sp"
android:textStyle="bold" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/firebase_nume"
android:rowCount="3"
android:columnCount="2">
<androidx.cardview.widget.CardView
android:id="#+id/add_pacient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#39ECC8"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stat_add" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adaugare Pacient"
android:textAlignment="center"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cautare_pacient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stat_search" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cautare Pacient"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/transf_pacient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stat_transf" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Transfer Pacient"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/stergere_pacient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/purple_200"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_photo_camera_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WORK IN PROGRESS"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/logout_pacient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/purple_200"
android:layout_row="2"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_photo_camera_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NUME.EXE"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/afisare_pacient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/purple_200"
android:layout_row="2"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_photo_camera_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INCA E"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#drawable/background1"
tools:context=".Login">
<TextView
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="84dp"
android:text="Login"
android:textColor="#E30F0F"
android:textSize="38sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/ID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="148dp"
android:autofillHints=""
android:background="#040404"
android:drawableStart="#drawable/ic_action_id"
android:ems="10"
android:fontFamily="#font/roboto"
android:hint="id"
android:inputType="textPersonName"
android:padding="10dp"
android:textColor="#FFFFFF"
android:textColorHint="#FAF9F9"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/Pw"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="12dp"
android:background="#040404"
android:drawableStart="#drawable/ic_action_password"
android:ems="10"
android:fontFamily="#font/roboto"
android:hint="password"
android:inputType="textPassword"
android:padding="10dp"
android:textColor="#FFFFFF"
android:textColorHint="#FAF9F9"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ID"
android:autofillHints="" />
<Button
android:id="#+id/loginBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="144dp"
android:text="login"
app:backgroundTint="#E30F0F"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Pw" />
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="48dp"
android:progressDrawable="#drawable/background1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/loginBtn" />
</androidx.constraintlayout.widget.ConstraintLayout>
The problem seems to come from here:
final FirebaseUser user=firebaseAuth.getCurrentUser();
String finaluser=(user).getEmail();
It looks like firebaseAuth.getCurrentUser() returns null, which then makes the (user).getEmail() fail.
If you're not sure that the user is signed in, you can check whether it is by adding a check:
final FirebaseUser user=firebaseAuth.getCurrentUser();
if (user != null) {
String finaluser=(user).getEmail();
...
If you think the user should be signed in, then it could be that this code runs before Firebase has established that fact. If that's the case, consider using an auth state listener to ensure your code only runs after the user's sign-in state has been established.

Radio button as tabs highlight when selected (Android Studio)

I am trying to create radio buttons that allows the users to select one of the three options. Once selected, the option should have a border, while the others do not.
Here is an image of what I am trying to create:
I'm not sure how to go about this. Any suggestions are greatly appreciated.
You could create a group of objects (which are the options) and programmatically ensure that only one of them can be selected.
selection could be presented as you wish it would be, I'd give a code example that imitates approximately the image you've attached. here's the structure:
XML file: CardViews with base of invisible FrameLayout (will be functioning as stroke), above the base is the cards' content
Java Class: setChecked(MaterialCardView selected) method that selects the chosen card (making it's 'stroke' visible) and checkedCard() that returns the selected card
so here's the code:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#color/parentBackground"
tools:context=".MainActivity">
<com.google.android.material.card.MaterialCardView
android:id="#+id/public_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardBackgroundColor="#color/cardBackground"
app:cardCornerRadius="5dp">
<FrameLayout
android:id="#+id/public_stroke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/selectedCardStroke"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/cardBackground">
<com.github.abdularis.civ.CircleImageView
android:id="#+id/card1Icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:src="#mipmap/ic_public" />
<TextView
android:id="#+id/card1Label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/card1Icon"
android:text="Public Profile"
android:textAllCaps="false"
android:textColor="#color/cardLabelColor"
android:textSize="35sp" />
<TextView
android:id="#+id/card1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/card1Label"
android:layout_alignStart="#id/card1Label"
android:text="Everyone can see your account. \nIncluding non followers."
android:textAllCaps="false"
android:textColor="#color/cardTextColor"
android:textSize="15sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/friends_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/public_card"
android:layout_margin="10dp"
app:cardBackgroundColor="#color/cardBackground"
app:cardCornerRadius="5dp">
<FrameLayout
android:id="#+id/friends_stroke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/selectedCardStroke"
android:visibility="invisible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/cardBackground">
<com.github.abdularis.civ.CircleImageView
android:id="#+id/card2Icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:src="#mipmap/ic_friends" />
<TextView
android:id="#+id/card2Label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/card2Icon"
android:text="Friends Only"
android:textAllCaps="false"
android:textColor="#color/cardLabelColor"
android:textSize="35sp" />
<TextView
android:id="#+id/card2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/card2Label"
android:layout_alignStart="#id/card2Label"
android:text="Connections nly. Only your friends \nand friends of friends can see your account."
android:textAllCaps="false"
android:textColor="#color/cardTextColor"
android:textSize="15sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/private_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/friends_card"
android:layout_margin="10dp"
app:cardBackgroundColor="#color/cardBackground"
app:cardCornerRadius="5dp">
<FrameLayout
android:id="#+id/private_stroke"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/selectedCardStroke"
android:visibility="invisible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/cardBackground">
<com.github.abdularis.civ.CircleImageView
android:id="#+id/card3Icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:src="#mipmap/ic_private" />
<TextView
android:id="#+id/card3Label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/card3Icon"
android:text="Private"
android:textAllCaps="false"
android:textColor="#color/cardLabelColor"
android:textSize="35sp" />
<TextView
android:id="#+id/card3Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/card3Label"
android:layout_alignStart="#id/card3Label"
android:text="Only you can see your account."
android:textAllCaps="false"
android:textColor="#color/cardTextColor"
android:textSize="15sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
MainActivity.java:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.google.android.material.card.MaterialCardView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
public MaterialCardView cPublic, cFriends, cPrivate;
public FrameLayout sPublic, sFriends, sPrivate;
public ArrayList<MaterialCardView> cards;
public ArrayList<FrameLayout> strokes;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cards = new ArrayList<>();
strokes = new ArrayList<>();
cPublic = findViewById(R.id.public_card);
cFriends = findViewById(R.id.friends_card);
cPrivate = findViewById(R.id.private_card);
cards.add(cPublic);
cards.add(cFriends);
cards.add(cPrivate);
sPublic = findViewById(R.id.public_stroke);
sFriends = findViewById(R.id.friends_stroke);
sPrivate = findViewById(R.id.private_stroke);
strokes.add(sPublic);
strokes.add(sFriends);
strokes.add(sPrivate);
cPublic.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
setChecked(cPublic);
}
});
cFriends.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
setChecked(cFriends);
}
});
cPrivate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
setChecked(cPrivate);
}
});
}
public void setChecked(MaterialCardView selected) {
int index = cards.indexOf(selected);
FrameLayout stroke = strokes.get(index);
stroke.setVisibility(View.VISIBLE);
for (FrameLayout s : strokes) {
if (!s.equals(stroke)) {
s.setVisibility(View.INVISIBLE);
}
}
}
public MaterialCardView checkedCard() {
int index = 0;
for (FrameLayout s : strokes) {
if (s.getVisibility() == View.VISIBLE) {
index = strokes.indexOf(s);
}
}
return cards.get(index);
}
}
Hope it could help you (:

JSON text not autosizing in textview (uniformly in horizontal and vertical direction)

I'm trying to fetch text from a JSON file uploaded in my Firebase database, but when the text lines are fetched, they aren't auto-sized (wrt x and y-axis), although I used autoSizeTextType = uniform along with added parameters. Blank spaces are still present on the right side (as one can see from the snapshots). I've used 3rd party Gradle dependencies, but, they also don't work out well. So, pls help me out and tell me solution based on my code.
Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".CourseDetail">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing"
android:layout_width="match_parent"
android:layout_height="350dp"
android:fitsSystemWindows="true"
app:contentScrim="#262628"
app:expandedTitleTextAppearance="#android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/img_course"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:title="Course Name"
app:titleTextColor="#ffffff" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="12dp"
android:text="DESCRIPTION"
android:textColor="#262628"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<TextView
android:id="#+id/course_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:autoSizeTextType="uniform"
android:fitsSystemWindows="true"
android:lineSpacingMultiplier="1.5"
android:text="Description "
android:textColor="#android:color/black"
android:autoSizeMinTextSize="15sp"
android:autoSizeMaxTextSize="20sp"
android:autoSizeStepGranularity="1sp"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="12dp"
android:text="DEGREE INFROMATION"
android:textColor="#262628"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<TextView
android:id="#+id/degree_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:lineSpacingMultiplier="1.5"
android:padding="12dp"
android:text="Description"
android:textColor="#android:color/black"
android:textSize="14sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="12dp"
android:text="JOB SCOPE"
android:textColor="#262628"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<TextView
android:id="#+id/job_scope"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:lineSpacingMultiplier="1.5"
android:padding="12dp"
android:text="Description"
android:textColor="#android:color/black"
android:textSize="14sp" />
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Activity.java
package com.example.shubhojit.careersafter10th;
import android.support.annotation.NonNull;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.shubhojit.careersafter10th.Model.Courses_After10th;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
public class CourseDetail extends AppCompatActivity {
TextView course_description,deg_info,job_scope;
ImageView courseImage;
CollapsingToolbarLayout collapsingToolbarLayout;
String courseId="";
FirebaseDatabase database;
DatabaseReference coursedetail;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course_detail);
database = FirebaseDatabase.getInstance();
coursedetail = database.getReference("Courses_After10th");
course_description = (TextView)findViewById(R.id.course_description);
deg_info = (TextView)findViewById(R.id.degree_information);
job_scope = (TextView)findViewById(R.id.job_scope);
courseImage = (ImageView)findViewById(R.id.img_course);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing);
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppbar);
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppbar);
if(getIntent() != null)
courseId = getIntent().getStringExtra("CourseId");
if(!courseId.isEmpty())
{
getDetailCourse(courseId);
}
}
private void getDetailCourse(String courseId) {
coursedetail.child(courseId).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
Courses_After10th course = dataSnapshot.getValue(Courses_After10th.class);
Picasso.with(getBaseContext()).load(course.getImage()).into(courseImage);
collapsingToolbarLayout.setTitle(course.getName());
deg_info.setText(course.getDegree_Information());
job_scope.setText(course.getJob_Scope());
course_description.setSingleLine(false);
course_description.setText(course.getDescription());
course_description.setEllipsize(TextUtils.TruncateAt.END);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
TextView does not provide Justify kinda alignment available in Word kinda tools.
To Justify text, instead use WebView with HTML content. Convert your text into HTML tags with proper alignment and styling. And then load the content in WebView as HTML.

Dynamically generated delete button does not respond to an OnclickListener(Android JAVA)

I created an app that dynamically adds an edittext field to the view by clicking an Add button and deletes it by clicking a delete button. I created a separate xml file called field.xml that is called up when a new edittext field is added to the view. But the delete button does not remove this edittext field when clicked. What am I missing in the code I have tried most options but to no avail.
Here is the main java file
SchoolSearchSetup.java
import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.view.View;
import android.widget.Toast;
public class SchoolSearchSetup extends AppCompatActivity implements View.OnClickListener {
private EditText searchSchoolID;
private Button searchSchoolButtonID;
private ListView listOfSchoolsID;
private Button openNewschoolID;
private LinearLayout schoolSetupLayout;
private Button addNewClass;
private EditText classNameEditText;
private Button deleteButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_school_search_setup);
findAllViewsID();
initializeListenners();
}
public void findAllViewsID(){
classNameEditText = findViewById(R.id.classNameText);
addNewClass = findViewById(R.id.addNewClassButton);
schoolSetupLayout = findViewById(R.id.schoolSetupLayout);
searchSchoolID = findViewById(R.id.searchSchoolID);
searchSchoolButtonID = findViewById(R.id.searchSchoolButtonID);
listOfSchoolsID = findViewById(R.id.listOfSchoolsID);
openNewschoolID = findViewById(R.id.openNewschoolID);
deleteButton = findViewById(R.id.delete_button);
}
public void initializeListenners(){
openNewschoolID.setOnClickListener(SchoolSearchSetup.this);
addNewClass.setOnClickListener(SchoolSearchSetup.this);
deleteButton.setOnClickListener(SchoolSearchSetup.this);
}
public void addNewClass(){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.field, null);
schoolSetupLayout.addView(rowView, schoolSetupLayout.getChildCount() -1);
}
#Override
public void onClick(View view) {
switch(view.getId()){
case R.id.openNewschoolID:
displaySchoolSetUpForms();
break;
case R.id.addNewClassButton:
addNewClass();
break;
case R.id.delete_button:
schoolSetupLayout.removeView((View) view.getParent());
}
}
private void displaySchoolSetUpForms() {
schoolSetupLayout.setVisibility(View.VISIBLE);
}
}
The main XML file
activity.school_search_setup.xml
<?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="wrap_content"
tools:context="com.example.demeainc.demea.MainActivity"
android:orientation="vertical"
android:background="#color/backgroundColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<ImageView
android:id="#+id/backArrowClassView"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_arrow_class"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:text="Search your school."
android:gravity="center"
android:textSize="25dp" />
<android.support.v7.widget.CardView
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp">
<EditText
android:id="#+id/searchSchoolID"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="#drawable/ic_search_black_24dp"
android:hint="Search"/>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="20dp">
<Button
android:id="#+id/searchSchoolButtonID"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_marginLeft="60dp"
android:text="Search"
android:textColor="#ffff"
android:background="#color/colorPrimary"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp">
<android.support.v7.widget.CardView
android:layout_width="300dp"
android:layout_height="wrap_content">
<ListView
android:id="#+id/listOfSchoolsID"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#android:color/transparent"
android:cacheColorHint="#color/ligtherDarkGrey"
android:divider="#CCCCCC"
android:dividerHeight="2dp"
android:paddingLeft="2dp" >
</ListView>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical">
<Button
android:id="#+id/openNewschoolID"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_marginLeft="60dp"
android:background="#color/colorPrimary"
android:text="Open New School"
android:textColor="#ffff"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/schoolSetupLayout"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/schoolSetupText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="School Setup"
android:textSize="20dp"
android:layout_marginLeft="50dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/classNameText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:hint="Class name, e.g Grade one" />
<Button
android:id="#+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#android:drawable/ic_delete"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:id="#+id/addNewClassButton"
android:layout_marginTop="15dp"
android:layout_marginLeft="50dp"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Add new class"
android:textColor="#ffff"
android:background="#color/colorPrimary"/>
<Button
android:id="#+id/nextButton"
android:layout_marginTop="25dp"
android:layout_marginLeft="8dp"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Next"
android:textColor="#ffff"
android:background="#color/green"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Here is the Field.xml file for the edit text to be added. Both the field.xml and the activity.school_search_setup.xml share the same IDs.
Field.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/schoolSetupLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/classNameText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:hint="Class name, e.g Grade one" />
<Button
android:id="#+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#android:drawable/ic_delete"/>
</LinearLayout>
</LinearLayout>
Have you tried using
setVisibility(View.GONE);
Update:
Try this code block:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Button btn = new Button(this);
btn.setId(i);
final int id_ = btn.getId();
btn.setText("button " + id_);
btn.setBackgroundColor(Color.rgb(80, 80, 90));
linear.addView(btn, params);
btn1 = ((Button) findViewById(id_));
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(view.getContext(),
"Button clicked index = " + id_, Toast.LENGTH_SHORT)
.show();
}
});

Android ImageButton does not display image

I am new to java and I am developing a simple mediaplayer: I have problems with two image buttons: when i run the app the relative images are not displayed. This is my code:
JAVA:
package lukes.mediaplayer;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.app.Activity;
public class alpha extends Activity implements View.OnClickListener {
SeekBar seekBar_alpha;
ImageButton btPlay_alpha;
ImageButton btStop_alpha;
MediaPlayer mp;
Handler seekHandler = new Handler();
ImageView display;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alpha);
display = (ImageView) findViewById(R.id.imagetop);
display.setOnClickListener(this);
getInit();
seekUpdation();
}
public void getInit() {
seekBar_alpha = (SeekBar) findViewById(R.id.seekBar_alpha);
btPlay_alpha = (ImageButton) findViewById(R.id.btPlay_alpha);
btStop_alpha = (ImageButton) findViewById(R.id.btStop_alpha);
btPlay_alpha.setOnClickListener(this);
btStop_alpha.setOnClickListener(this);
mp = MediaPlayer.create(this, R.raw.alpha_audio);
seekBar_alpha.setMax(mp.getDuration());
}
Runnable run = new Runnable() {
#Override
public void run() {
seekUpdation();
}
};
public void seekUpdation() {
seekBar_alpha.setProgress(mp.getCurrentPosition());
seekHandler.postDelayed(run, 1000);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.imagetop:
Intent intent = new Intent (alpha.this, alpha_img.class);
startActivity(intent);
case R.id.btPlay_alpha:
mp.start();
break;
case R.id.btStop_alpha:
mp.pause();
}
}
#Override
protected void onPause(){
super.onPause();
if (mp!=null && mp.isPlaying()){
mp.pause();
}
}
}
The "btPlay_alpha" and "btStop_alpha" image buttons does not display their image. Can you help me to fix that? Thank you!
Hey guys, I add the XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context=".alpha">
<android.support.design.widget.AppBarLayout
android:id="#+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="350dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<ImageButton
android:id="#+id/imagetop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#drawable/alpha"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:lineSpacingExtra="8dp"
android:padding="16dp"
android:text="#string/alpha_title"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageButton
android:id="#+id/btStop_alpha"
android:layout_width="60dp"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:backgroundTint="#color/lightRed"
android:elevation="6dp"
android:padding="16dp"
app:srcCompat="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/btPlay_alpha"
android:layout_width="60dp"
android:layout_height="55dp"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_toEndOf="#+id/btStop_alpha"
android:layout_toRightOf="#+id/btStop_alpha"
android:backgroundTint="#color/lightRed"
android:elevation="6dp"
app:srcCompat="#android:drawable/ic_media_play" />
<SeekBar
android:id="#+id/seekBar_alpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/btPlay_alpha"
android:layout_toRightOf="#+id/btPlay_alpha"
android:max="100" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:lineSpacingExtra="8dp"
android:padding="16dp"
android:text="#string/alpha_text"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Thank you for your support!
I see youre extending Activity Instead of AppCompatActivity. In your xml, you are setting attribute srcCompat; make sure As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat .
you need to add vectorDrawables.useSupportLibrary = true to your build.gradle file
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}

Categories