Android Sqlite BaseAdapter搜索视图和列表错误

时间:2018-10-04 01:44:37

标签: android searchview custom-arrayadapter

我正在尝试显示显示数据库值的列表视图,并且需要搜索那些项目,单击时将使用该列表项目的数据库ID。我尝试了这段代码,但是我的应用崩溃了。

我的数据库

enter image description here

这是我的数据库类,可以从数据库中获取结果

package com.me.doctor.doctor_me;

    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteQueryBuilder;

    import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

    public class DatabaseOperation extends SQLiteAssetHelper {

        public static final int DB_VERSION = 1;
        public static final String DB_NAME= "app_db.db";

        public DatabaseOperation(Context context) {
            super(context, DB_NAME,null, DB_VERSION);
        }

        // Verify user Loggin
        public boolean loginUser(String email, String password) {
            SQLiteDatabase db = this.getReadableDatabase();
            SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

            String sqlTables = "user";
            qb.setTables(sqlTables);

            Cursor c = qb.query(db,null,"email = ? AND password = ?",new String[]{email,password},null,null,null);

            if (c.getCount() > 0) {
                return true;
            } else {
                return false;
            }
        }


        //RETRIEVE DATA AND FILTER
        public Cursor retrieve(String searchTerm)
        {
            SQLiteDatabase db = getReadableDatabase();
            String[] columns = {"d_id","d_name","d_gender","d_hospital","d_category"};
            Cursor c=null;

            if(searchTerm != null && searchTerm.length()>0)
            {
                String sql="SELECT * FROM doctor WHERE d_name LIKE '%"+searchTerm+"%'";
                c=db.rawQuery(sql,null);
                return c;
            }

            c=db.query("doctor",columns,null,null,null,null,null);
            return c;
        }
    }

这是我的医生课

        package com.me.doctor.doctor_me;

    public class Doctor {
        int id;
        String name, category, gender, hospital;

        public Doctor(int id, String name, String category, String gender, String hospital) {
            this.id = id;
            this.name = name;
            this.category = category;
            this.gender = gender;
            this.hospital = hospital;
        }
        public Doctor(){

        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getCategory() {
            return category;
        }

        public void setCategory(String category) {
            this.category = category;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }

        public String getHospital() {
            return hospital;
        }

        public void setHospital(String hospital) {
            this.hospital = hospital;
        }
    }

这是我的自定义阵列适配器类

        package com.me.doctor.doctor_me;

    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    import android.widget.Toast;

    import java.util.ArrayList;

    public class CustomAdapter extends BaseAdapter {
        Context c;
        ArrayList<Doctor> doctors;
        LayoutInflater inflater;

        public CustomAdapter(Context c, ArrayList<Doctor> doctors) {
            this.c = c;
            this.doctors = doctors;
        }

        @Override
        public int getCount() {
            return doctors.size();
        }

        @Override
        public Object getItem(int i) {
            return doctors.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            if(inflater==null)
            {
                inflater= (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            }
            if(view==null)
            {
                view=inflater.inflate(R.layout.layout_item,viewGroup,false);
            }

            TextView nameTxt= view.findViewById(R.id.list_name);
            nameTxt.setText(doctors.get(i).getName());

            final int pos=i;

            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(c,doctors.get(pos).getId(),Toast.LENGTH_SHORT).show();
                }
            });

            return view;
        }
    }

这是我的控制器类

package com.me.doctor.doctor_me;

 import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;

 import java.util.ArrayList;

 public class SearchActivity extends AppCompatActivity {



ListView lv;
SearchView sv;
EditText nameEditText;
Button retrieveBtn;
CustomAdapter adapter;
ArrayList<Doctor> doctors=new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    lv = findViewById(R.id.lv);
    sv = findViewById(R.id.search_view);

    adapter = new CustomAdapter(this, doctors);

    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            getDoctors(newText);
            return false;
        }
    });
}

private void getDoctors(String searchTerm)
{
    doctors.clear();

    DatabaseOperation databaseOperation = new DatabaseOperation(this);
    Doctor d = null;
    Cursor c = databaseOperation.retrieve(searchTerm);
    while (c.moveToNext())
    {
        int id = c.getInt(0);
        String name=c.getString(1);
        String gender=c.getString(2);
        String hospital=c.getString(3);
        String category=c.getString(4);

        d =new Doctor();
        d.setId(id);
        d.setName(name);
        d.setGender(gender);
        d.setCategory(category);
        d.setHospital(hospital);

        doctors.add(d);
    }

    lv.setAdapter(adapter);

}
}

这是我的布局文件

layout_item.xml通过自定义适配器膨胀

        <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:cardElevation="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="horizontal"
            android:layout_margin="8dp">

            <ImageView
                android:src="@drawable/ic_person_pin_black_24dp"
                android:layout_width="70dp"
                android:layout_height="70dp" />
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="9"
                android:orientation="vertical"
                >
                <TextView
                    android:id="@+id/list_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical|start"
                    android:textAllCaps="true"
                    android:textStyle="bold"
                    android:layout_marginLeft="10dp"
                    android:text="Sahan"/>
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>

这是Activity_search.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"
        tools:context=".SearchActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

            <include layout="@layout/content_main" />

        </android.support.design.widget.AppBarLayout>

    </RelativeLayout>

这是内容xml的好名content_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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".SearchActivity"
    tools:showIn="@layout/activity_search">

    <android.support.v7.widget.SearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:queryHint="Search.."
        >

    </android.support.v7.widget.SearchView>

    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/search_view"
        android:layout_alignParentStart="true"
        android:layout_marginTop="-64dp"></ListView>
</RelativeLayout>

我的日志猫是

        10-04 07:24:58.340 5380-5380/com.me.doctor.doctor_me E/AppCompatResources: Failed to inflate ColorStateList, leaving it to the framework
        java.lang.RuntimeException: Failed to resolve attribute at index 0
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.support.v7.content.res.AppCompatColorStateListInflater.inflate(AppCompatColorStateListInflater.java:114)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXmlInner(AppCompatColorStateListInflater.java:88)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXml(AppCompatColorStateListInflater.java:67)
            at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:116)
            at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:74)
            at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:170)
            at android.support.v7.widget.AppCompatTextHelper.onSetTextAppearance(AppCompatTextHelper.java:296)
            at android.support.v7.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:162)
            at android.support.v4.widget.TextViewCompat$TextViewCompatBaseImpl.setTextAppearance(TextViewCompat.java:168)
            at android.support.v4.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:648)
            at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:635)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:257)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:187)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
            at com.me.doctor.doctor_me.MainActivity.onCreate(MainActivity.java:37)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    10-04 07:24:58.384 5380-5380/com.me.doctor.doctor_me E/AppCompatResources: Failed to inflate ColorStateList, leaving it to the framework
        java.lang.RuntimeException: Failed to resolve attribute at index 0
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.support.v7.content.res.AppCompatColorStateListInflater.inflate(AppCompatColorStateListInflater.java:114)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXmlInner(AppCompatColorStateListInflater.java:88)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXml(AppCompatColorStateListInflater.java:67)
            at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:116)
            at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:74)
            at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:170)
            at android.support.v7.widget.AppCompatTextHelper.onSetTextAppearance(AppCompatTextHelper.java:296)
            at android.support.v7.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:162)
            at android.support.v4.widget.TextViewCompat$TextViewCompatBaseImpl.setTextAppearance(TextViewCompat.java:168)
            at android.support.v4.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:648)
            at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:635)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:257)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:187)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
            at com.me.doctor.doctor_me.MainActivity.onCreate(MainActivity.java:37)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

        10-04 07:25:02.898 5380-5380/com.me.doctor.doctor_me E/AppCompatResources: Failed to inflate ColorStateList, leaving it to the framework
        java.lang.RuntimeException: Failed to resolve attribute at index 0
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.support.v7.content.res.AppCompatColorStateListInflater.inflate(AppCompatColorStateListInflater.java:114)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXmlInner(AppCompatColorStateListInflater.java:88)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXml(AppCompatColorStateListInflater.java:67)
            at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:116)
            at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:74)
            at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:170)
            at android.support.v7.widget.AppCompatTextHelper.onSetTextAppearance(AppCompatTextHelper.java:296)
            at android.support.v7.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:162)
            at android.support.v4.widget.TextViewCompat$TextViewCompatBaseImpl.setTextAppearance(TextViewCompat.java:168)
            at android.support.v4.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:648)
            at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:635)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:257)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:187)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
            at com.me.doctor.doctor_me.SearchActivity.onCreate(SearchActivity.java:30)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    10-04 07:25:02.909 5380-5380/com.me.doctor.doctor_me E/AppCompatResources: Failed to inflate ColorStateList, leaving it to the framework
        java.lang.RuntimeException: Failed to resolve attribute at index 0
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.support.v7.content.res.AppCompatColorStateListInflater.inflate(AppCompatColorStateListInflater.java:114)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXmlInner(AppCompatColorStateListInflater.java:88)
            at android.support.v7.content.res.AppCompatColorStateListInflater.createFromXml(AppCompatColorStateListInflater.java:67)
            at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:116)
            at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:74)
            at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:170)
            at android.support.v7.widget.AppCompatTextHelper.onSetTextAppearance(AppCompatTextHelper.java:296)
            at android.support.v7.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:162)
            at android.support.v4.widget.TextViewCompat$TextViewCompatBaseImpl.setTextAppearance(TextViewCompat.java:168)
            at android.support.v4.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:648)
            at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:635)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:257)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:187)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
            at com.me.doctor.doctor_me.SearchActivity.onCreate(SearchActivity.java:30)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    10-04 07:25:02.941 5380-5380/com.me.doctor.doctor_me D/AndroidRuntime: Shutting down VM
    10-04 07:25:02.941 5380-5380/com.me.doctor.doctor_me E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.me.doctor.doctor_me, PID: 5380
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.doctor.doctor_me/com.me.doctor.doctor_me.SearchActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
         Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:201)
            at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)
            at com.me.doctor.doctor_me.SearchActivity.onCreate(SearchActivity.java:32)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
            at android.app.ActivityThread.access$800(ActivityThread.java:151) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:135) 
            at android.app.ActivityThread.main(ActivityThread.java:5254) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:372) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

0 个答案:

没有答案