0

I am getting tired fixing this problem. the app does not execute it always show me this error Binary XML file line #26: Error inflating class EditText. I don't understand how to fix this problem. This is my activity_members.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">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/newMeetScreen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="visible"
        tools:layout_editor_absoluteX="384dp">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="0dp"
            android:layout_height="54dp"
            android:src="@drawable/gradient"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <EditText
            android:id="@+id/edit_search"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="11dp"
            android:layout_marginTop="7dp"
            android:layout_marginEnd="13dp"
            android:layout_marginBottom="7dp"
            android:background="@drawable/radius_edit_text"
            android:drawableLeft="@drawable/ic_search"
            android:drawablePadding="3dp"
            android:hint="Поиск"
            android:imeOptions="actionGo"
            android:inputType="text"
            android:textColor="@color/colorPrimaryDark"
            android:textColorHint="#9b9a9a"
            android:textSize="20sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/btnDone"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/btnDone"
            android:layout_width="52dp"
            android:layout_height="50dp"
            android:background="@android:drawable/list_selector_background"
            android:src="@drawable/ic_done"
            android:textColor="@color/colorProjectTextWhite"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/edit_search"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

    <android.support.v7.widget.RecyclerView
        android:background="@color/colorBackgroundLight"
        android:id="@+id/membersList"
        android:scrollbars="vertical"
        android:layout_marginTop="0dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

And this is my MembersActivity.java class.

public class MembersActivity extends AppCompatActivity {
    private static final int REQUEST_CODE_READ_CONTACTS = 1;
    private static boolean READ_CONTACTS_GRANTED = false;
    RecyclerView members;
    ArrayList<String> contacts = new ArrayList<String>();
    ArrayList<String> tell = new ArrayList<String>();
    UserAdapter adapter;
    User user;
   ArrayList<User> users = new ArrayList<>();
    ImageButton btnDone;
    StringBuilder stringBuilder = null;
    EditText editSearch;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_members);
        members = findViewById(R.id.membersList);
        btnDone = findViewById(R.id.btnDone);
        editSearch = findViewById(R.id.edit_search);
        int hasReadContactPermission = ContextCompat.checkSelfPermission(Objects.requireNonNull(this), Manifest.permission.READ_CONTACTS);
        if (hasReadContactPermission == PackageManager.PERMISSION_GRANTED) {
            READ_CONTACTS_GRANTED = true;

        } else {

            ActivityCompat.requestPermissions(Objects.requireNonNull(this), new
                    String[]{Manifest.permission.READ_CONTACTS}, REQUEST_CODE_READ_CONTACTS);

        } 
        if (READ_CONTACTS_GRANTED) {
            getContacts();
        }

        btnDone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                stringBuilder = new StringBuilder();
                int i=0;
                char ch = ',';
                do{
                    User user = adapter.checkedUsers.get(i);
                    if(i == adapter.checkedUsers.size()-1) ch = '.';
                    stringBuilder.append(user.getName() + ch);
                    if(i != adapter.checkedUsers.size() -1) {
                        stringBuilder.append("\n");
                    }
                    i++;

                } while (i < adapter.checkedUsers.size());
                if(adapter.checkedUsers.size() > 0) {
                    Intent intent = new Intent();
                    intent.putExtra("names", stringBuilder.toString());
                    setResult(RESULT_OK, intent);
                    finish();


                } else {
                    Toast.makeText(MembersActivity.this, "Пожалуйста, выберите друзей", Toast.LENGTH_LONG).show();

                }
            }
        });
        editSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                adapter.getFilter().filter(charSequence);
                return;

            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

    }

    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE_READ_CONTACTS:
                if (grantResults.length > 0 && grantResults[0] ==
                        PackageManager.PERMISSION_GRANTED) {
                    READ_CONTACTS_GRANTED = true;

                }
        }
        if (READ_CONTACTS_GRANTED) {
            getContacts();
        }
        else {
            Toast.makeText(this, "Требуется установить разрешения", Toast.LENGTH_LONG).show();
        }
    }

    public void getContacts() {
        Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
        String _ID = ContactsContract.Contacts._ID;
        String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME;
        String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER;

        Uri PhoneCONTENT_URI =
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        String Phone_CONTACT_ID =
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID;
        String NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER;

        StringBuffer output = new StringBuffer();
        ContentResolver contentResolver = Objects.requireNonNull(this).getContentResolver();
        Cursor cursor = contentResolver.query(CONTENT_URI, null, null, null, null);

        if (cursor.getCount() > 0) {

            while (cursor.moveToNext()) {
                String contact_id = cursor.getString(cursor.getColumnIndex(_ID));
                String name = cursor.getString(cursor.getColumnIndex(DISPLAY_NAME));
                int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER)));

                if (hasPhoneNumber > 0) {
                    contacts.add(name);

                    Cursor phoneCursor =
                            contentResolver.query(PhoneCONTENT_URI, null,
                                    Phone_CONTACT_ID + " = ?", new String[]{contact_id}, null);
                    while (phoneCursor.moveToNext()) {
                        String phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER));
                        tell.add(phoneNumber);
                    }
                }
            }
        }

        if(tell.size() > contacts.size()) {
            for(int i=0; i <contacts.size(); i++) {
                user = new User(tell.get(i), contacts.get(i));
                users.add(user);
            }
        } else {
            for(int i=0; i < tell.size(); i++) {
                user = new User(tell.get(i), contacts.get(i));
                users.add(user);
            }
        }

        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
        adapter = new UserAdapter(users, this);
        members.setLayoutManager(mLayoutManager);
        members.setItemAnimator(new DefaultItemAnimator());
        members.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        members.setAdapter(adapter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }


}

Please, help me fix this problem.

Android
  • 1,420
  • 4
  • 13
  • 23
anna
  • 433
  • 7
  • 18
  • please post the full stack trace of the exception, it usually contains a "caused by" prior exception showing the reason for the inflate to fail – marmor Nov 26 '18 at 08:04
  • also, are `radius_edit_text` and `ic_search` regular png drawables, or are they xml files? – marmor Nov 26 '18 at 08:05

1 Answers1

0

You need to set the width and height of your EditText in your layout file you cannot set these properties to 0dp. If you want to set this according to screen size then you can use layout_weight in your xml.Here you can know about layout_weight usage

If you are using constraintLayout in your layout you can see this link. Responsive layout designing with constraint layout

Humayun
  • 68
  • 7