当前位置: 首页 > 知识库问答 >
问题:

Android-binary XML文件第10行:inflating类时出错

能文华
2023-03-14
    null
 <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>
RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.viewProfile);
relativeLayout.setOnClickListener(v -> {
    Intent intent1 = new Intent(ChatActivity.this, FriendProfileViewActivity.class);
    intent1.putExtra("friendId", friendId);
    startActivity(intent1);
    });

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();
        });
    }
}

共有1个答案

林英锐
2023-03-14

好的,我很快运行了您的代码,得到了这个堆栈跟踪:

 Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class de.hdodenhof.circleimageview.CircleImageView
     Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class de.hdodenhof.circleimageview.CircleImageView
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:656)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:798)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at za.co.Test.testit.MainActivity.onCreate(MainActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:6910)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2757)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2875)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1578)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6623)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
     Caused by: java.lang.IllegalArgumentException: ScaleType FIT_CENTER not supported.
        at de.hdodenhof.circleimageview.CircleImageView.setScaleType(CircleImageView.java:134)

从friendProfilePic中删除缩放类型修正了错误。

除此之外,他们在库的文档中记下了这一点:ScaleType总是center_crope,如果试图更改它,将会出现异常。这是(目前)根据设计,因为它是完美的配置文件图像。

 类似资料: