Я пытаюсь go выполнить другое действие, но приложение вылетает из-за этих ошибок. У меня есть 2 действия:
- Активный чат
- FriendProfileViewActivity
java .lang.RuntimeException: невозможно запустить действие ComponentInfo {com .mycompany.newchatapp / com.mycompany.newchatapp.Activities.FriendProfileViewActivity}: android .view.InflateException: двоичный XML строка файла # 10: двоичный XML строка файла # 10: ошибка наполнения класса Вызвано: android .view.InflateException: двоичный XML строка файла # 10: двоичный XML строка файла # 10: ошибка надувания класса Вызвано: android .view.InflateException: двоичный XML строка файла # 10: ошибка надувания класса Вызвано: java .lang.reflect.InvocationTargetException
Вот код XML ChatActivity.
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-10dp"
android:layout_marginTop="-10dp"
android:layout_marginEnd="-10dp"
android:layout_marginBottom="-10dp"
android:padding="5dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="40dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_back"
android:scaleType="centerCrop"/>
<RelativeLayout
android:id="@+id/viewProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/friendpic"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentStart="true"
android:layout_marginStart="-5dp"
android:layout_marginEnd="20dp"
android:src="@drawable/ic_user" />
<TextView
android:id="@+id/friendname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/friendpic"
android:fontFamily="@font/alegreya_sc_italic"
android:text="Username"
android:textSize="24sp" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/friendname"
android:layout_toEndOf="@+id/friendpic"
android:text="offline"
android:textSize="20sp" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
JAVA КОД для чата
RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.viewProfile);
relativeLayout.setOnClickListener(v -> {
Intent intent1 = new Intent(ChatActivity.this, FriendProfileViewActivity.class);
intent1.putExtra("friendId", friendId);
startActivity(intent1);
});
XML код для FriendProfileViewActivity XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="10dp"
tools:context=".Activities.FriendProfileViewActivity">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/friendProfilePic"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="30dp"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/friendProfileName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/friendProfilePic"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Friend Name"
android:textSize="28sp"
android:textStyle="bold|italic" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/friendProfileName"
android:layout_marginStart="-10dp"
android:layout_marginEnd="-10dp"
android:background="@android:color/black" />
<TextView
android:id="@+id/about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/friendProfileName"
android:layout_marginTop="10dp"
android:text="About Me: "
android:textSize="24sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/friendAboutMe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/friendProfileName"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_toEndOf="@+id/about"
android:text="@string/status"
android:textSize="26sp"
android:textStyle="italic" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/friendAboutMe"
android:layout_marginStart="-10dp"
android:layout_marginEnd="-10dp"
android:background="@android:color/black" />
<TextView
android:id="@+id/phoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/friendAboutMe"
android:layout_marginTop="10dp"
android:text="Phone Number: "
android:textSize="24sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/friendPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/friendAboutMe"
android:layout_marginTop="10dp"
android:layout_toEndOf="@+id/phoneNumber"
android:text="@string/fakeNumber"
android:textSize="26sp"
android:textStyle="italic" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/friendPhoneNumber"
android:layout_marginStart="-10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="-10dp"
android:background="@android:color/black" />
<Button
android:id="@+id/blockUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/button"
android:text="Block User"
android:textColor="@android:color/white"
android:textSize="24sp"
android:textStyle="italic" />
JAVA КОД FriendProfileViewActivity
public class FriendProfileViewActivity extends AppCompatActivity {
TextView name, about, phoneNumber;
Button blockUser;
CircleImageView profilepic;
DatabaseReference databaseReference;
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String friendId, friendPhoneNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friend_profile_view);
profilepic = findViewById(R.id.friendProfilePic);
name = findViewById(R.id.friendProfileName);
about = findViewById(R.id.friendAboutMe);
phoneNumber = findViewById(R.id.friendPhoneNumber);
blockUser = findViewById(R.id.blockUser);
Intent intent = getIntent();
friendId = intent.getStringExtra("friendId");
databaseReference = FirebaseDatabase.getInstance().getReference("Users").child(friendId);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
Users users = snapshot.getValue(Users.class);
name.setText(users.getUsername());
about.setText(users.getAboutMe());
phoneNumber.setText(users.getFullPhoneNumber());
// Glide.with(FriendProfileViewActivity.this).load(users.getProfilephotoURL())
// .fitCenter().placeholder(R.drawable.ic_user).into(profilepic);
friendPhoneNumber = users.getFullPhoneNumber();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
blockUser.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Block User");
builder.setIcon(R.drawable.ic_block);
builder.setCancelable(false);
builder.setMessage("Do you wan to block User?");
builder.setPositiveButton("Yes", (dialog, which) -> {
BlockList blockList = new BlockList(friendPhoneNumber);
DatabaseReference blockUser = FirebaseDatabase.getInstance().
getReference("BlockList").child(user.getUid());
blockUser.child(friendId).setValue(blockList);
BlockList blockList1 = new BlockList(user.getPhoneNumber());
blockUser = FirebaseDatabase.getInstance().
getReference("BlockList").child(friendId);
blockUser.child(user.getUid()).setValue(blockList1);
databaseReference = FirebaseDatabase.getInstance().getReference().child("ChatsList")
.child(user.getUid());
databaseReference.child(friendId).removeValue();
DatabaseReference friendChatList = FirebaseDatabase.getInstance().getReference().child("ChatsList")
.child(friendId);
friendChatList.child(user.getUid()).removeValue();
Intent intent1 = new Intent(FriendProfileViewActivity.this, MainScreen.class);
startActivity(intent1);
});
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss());
AlertDialog alertDialog = builder.create();
alertDialog.show();
});
}
}