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

无法启动活动ComponentInfo-二进制XML文件行#8:错误inflating类

夏侯楷
2023-03-14

我在尝试运行我的应用程序时收到了以下错误:无法启动活动ComponentInfo-二进制XML文件行#8:错误inflating类

以下是logcat消息:

09-10 00:07:18.029: E/AndroidRuntime(2591): FATAL EXCEPTION: main
09-10 00:07:18.029: E/AndroidRuntime(2591): Process: com.dooba.beta, PID: 2591
09-10 00:07:18.029: E/AndroidRuntime(2591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dooba.beta/com.dooba.beta.matchOptionActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.os.Looper.loop(Looper.java:136)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.ActivityThread.main(ActivityThread.java:5017)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at java.lang.reflect.Method.invokeNative(Native Method)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at java.lang.reflect.Method.invoke(Method.java:515)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at dalvik.system.NativeStart.main(Native Method)
09-10 00:07:18.029: E/AndroidRuntime(2591): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.Activity.setContentView(Activity.java:1929)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at com.dooba.beta.matchOptionActivity.onCreate(matchOptionActivity.java:55)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.Activity.performCreate(Activity.java:5231)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
09-10 00:07:18.029: E/AndroidRuntime(2591):     ... 11 more
09-10 00:07:18.029: E/AndroidRuntime(2591): Caused by: java.lang.reflect.InvocationTargetException
09-10 00:07:18.029: E/AndroidRuntime(2591):     at java.lang.reflect.Constructor.constructNative(Native Method)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
09-10 00:07:18.029: E/AndroidRuntime(2591):     ... 24 more
09-10 00:07:18.029: E/AndroidRuntime(2591): Caused by: java.lang.OutOfMemoryError
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.content.res.Resources.loadDrawable(Resources.java:2110)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.view.View.<init>(View.java:3554)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.widget.TextView.<init>(TextView.java:623)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.widget.Button.<init>(Button.java:107)
09-10 00:07:18.029: E/AndroidRuntime(2591):     at android.widget.Button.<init>(Button.java:103)

下面是活动代码

public class matchOptionActivity extends Activity{

     protected TextView mUserRetrieved;
        private String currentUserId;

        protected TextView mUserActivityNameRetrieved;
        protected TextView mUserNameRetrieved;
        protected TextView mUserAgeRetrieved;
        protected TextView mUserHeadlineRetrieved;
        String userGender = ParseUser.getCurrentUser().getString("Gender");
        String activityName = ParseUser.getCurrentUser().getString("ActivityName");
        Number maxDistance = ParseUser.getCurrentUser().getNumber(
                "Maximum_Distance");
        String userLookingGender = ParseUser.getCurrentUser().getString(
                "Looking_Gender");
        Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
        Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
        Number userage = ParseUser.getCurrentUser().getNumber("UserAge");




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.matchoption);

        ParseQuery<ParseUser> query = ParseUser.getQuery();

        // query.whereEqualTo("ActivityName",userActivitySelectionName);

        query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                .getObjectId());
        // users with Gender = currentUser.Looking_Gender
        query.whereEqualTo("Gender", userLookingGender);
        // users with Looking_Gender = currentUser.Gender
        query.whereEqualTo("Looking_Gender", userGender);
        query.setLimit(1);
        query.whereEqualTo("ActivityName", activityName);
        query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
        query.whereLessThanOrEqualTo("UserAge", maximumAge);
        query.orderByDescending("Name");

        query.findInBackground(new FindCallback<ParseUser>() {
            @Override
            public void done(List<ParseUser> objects,ParseException e) {

                for(int i=0;i<objects.size();i++){
                    // Do whatever you need to extract object from "users"
                    ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
                    query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                            .getObjectId());
                    // users with Gender = currentUser.Looking_Gender
                    query.whereEqualTo("Gender", userLookingGender);
                    // users with Looking_Gender = currentUser.Gender
                    query.whereEqualTo("Looking_Gender", userGender);
                    query.setLimit(1);
                    query.whereEqualTo("ActivityName", activityName);
                    query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
                    query.whereLessThanOrEqualTo("UserAge", maximumAge);

                    mUserNameRetrieved = (TextView) findViewById(R.id.tvmname1);

                    mUserNameRetrieved.setText(objects.get(i).get("Name").toString()); 



                }
    }//for loop
            });


        final Button idrinks = (Button) this.findViewById(R.id.btnQuickChat);
        idrinks.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                openConversation();
            }

            private void openConversation() {
                // TODO Auto-generated method stub
                  ParseQuery<ParseUser> query = ParseUser.getQuery();
                    query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                            .getObjectId());
                    // users with Gender = currentUser.Looking_Gender
                    query.whereEqualTo("Gender", userLookingGender);
                    // users with Looking_Gender = currentUser.Gender
                    query.whereEqualTo("Looking_Gender", userGender);
                    query.setLimit(1);
                    query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
                       query.whereLessThanOrEqualTo("UserAge", maximumAge);
                    query.whereEqualTo("ActivityName", activityName);
                    query.findInBackground(new FindCallback<ParseUser>() {
                        public void done(List<ParseUser> user, ParseException e) {
                            if (e == null) {
                                Intent intent = new Intent(
                                        getApplicationContext(), MessagingActivity.class);
                                intent.putExtra("Name", user.get(0).getObjectId());
                                startActivity(intent);
                            } else {
                                Toast.makeText(getApplicationContext(),
                                        "Error finding that user", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }
                    });


            }
        });




    final Button ibookingcontinue = (Button) this.findViewById(R.id.btncontinuebook);
    ibookingcontinue.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            continuebooking();
        }

        private void continuebooking() {
            // TODO Auto-generated method stub
            Intent intent = new Intent(matchOptionActivity.this, BookingMatchOptionActivity.class);
          startActivity(intent);
        }


    });
}
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main_activity_actions, menu);
        getActionBar().setDisplayShowTitleEnabled(false);



        return true;
    }

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.pageExperience:
            openPageExperience();
            return true;
        case R.id.pageMessaging:
            openPageMessage();
            return true;

        case R.id.pageEventsBooking:
            openPageBook();
            return true;

        case R.id.pageProfile:
            openPageProfile();
            return true;

        case R.id.pageReport:
            openPageReport();
            return true;

        case R.id.pageAbout:
            openPageAbout();
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}

private void openPageAbout() {
    // TODO Auto-generated method stub

}

private void openPageReport() {
    // TODO Auto-generated method stub

}

private void openPageProfile() {
    // TODO Auto-generated method stub
    Intent intent = new Intent(this, ProfileChange.class);
    startActivity(intent);

}

private void openPageBook() {
    // TODO Auto-generated method stub

}

private void openPageMessage() {
    // TODO Auto-generated method stub

}

private void openPageExperience() {
    // TODO Auto-generated method stub
    Intent intent = new Intent(this, MoodActivity.class);
    startActivity(intent);
}


}

匹配选项XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/blue_bac3"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btncontinuebook"
        android:layout_width="230dp"
        android:layout_height="50dp"
        android:layout_below="@+id/btnQuickChat"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:background="@drawable/blue_bac2"
        android:text="Continue with booking" />

    <TextView
        android:id="@+id/tactivityname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/btnQuickChat"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="106dp"
        android:text="Match With"
        android:textColor="#f2f2f2"
        android:textSize="24sp"
        android:textStyle="bold"
        android:typeface="serif" />

    <TextView
        android:id="@+id/tvmname1"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignTop="@+id/tactivityname"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="22dp"
        android:gravity="center"
        android:padding="3dp"
        android:textColor="#ADD8E6"
        android:textSize="28sp"
        android:textStyle="bold"
        android:typeface="serif" >

    </TextView>

    <Button
        android:id="@+id/btnQuickChat"
        android:layout_width="230dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/btncontinuebook"
        android:layout_alignParentTop="true"
        android:layout_marginTop="210dp"
        android:background="@drawable/gray_bac"
        android:text="Quick Chat"
        android:textColor="#000000" />

</RelativeLayout>

非常感谢您的帮助。谢谢

共有1个答案

毛峻
2023-03-14

您将获得一个OutOfMemory异常。它必须在android:background=“@drawable/blue_bac2”中。检查你的可绘制尺寸,尽量缩小资源的大小/尺寸,以及所有其他背景。

 类似资料: