0
votes

I am really puzzled by this error that I can't seem solve. Below is my code

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.doopisoft.dspots.adapter.ListViewAdapter;
import com.doopisoft.dspots.adapter.SearchAdapter;
import com.doopisoft.dspots.model.SearchModel;
import com.doopisoft.dspots.model.User;
import com.doopisoft.dspots.ui.main.ViewPagerAdapter;
import com.doopisoft.dspots.utils.SessionManager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import androidx.annotation.RequiresApi;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import java.util.List;
import butterknife.BindView;
import static com.doopisoft.dspots.utils.SessionManager.login;

public class MainActivity extends AppCompatActivity implements SearchAdapter.ItemListener{
    RecyclerView recyclerView;
    MaterialToolbar toolBar;
    AppBarLayout appBarLayout;
    ListViewAdapter listViewAdapter;
    SearchAdapter searchAdapter;
    ShowSearchView showSearchView;
    private ImageView image_search_back;
    private CardView card_search;
    private RelativeLayout view_search;
    String text = "";
    private View line_divider, toolbar_shadow;
    private EditText edit_text_search;
    List<SearchModel> modelsList, filterModels;
    List<SearchModel> cuisinesModels;
    @BindView(R.id.action_search)
    MenuItem actionSearch;
    @BindView(R.id.notification)
    MenuItem notification;
    boolean editTextChangedFromClick = false;
    ListView listView;
    SessionManager sessionManager;
    User user;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sessionManager = new SessionManager(MainActivity.this);
        user = sessionManager.getUserDetails("");
        showSearchView = new ShowSearchView();
        toolBar = (MaterialToolbar) findViewById(R.id.toolbar2);
        view_search = (RelativeLayout) findViewById(R.id.view_search);
        card_search = (CardView) findViewById(R.id.card_search);
        line_divider = findViewById(R.id.line_divider);
        toolbar_shadow = findViewById(R.id.toolbar_shadow);
        edit_text_search = (EditText) findViewById(R.id.edit_text_search);
        image_search_back = (ImageView) findViewById(R.id.image_search_back);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        appBarLayout = findViewById(R.id.appBar);
        listView = (ListView) findViewById(R.id.listView);
        TextView no_results = (TextView) findViewById(R.id.txtNoResultsFound);
        listView.setEmptyView(no_results);
        image_search_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                text = "";
                showSearchView.handleToolBar(MainActivity.this, card_search, toolBar, view_search, recyclerView, edit_text_search, line_divider);
                toolbar_shadow.setVisibility(View.VISIBLE);
                listViewAdapter = new ListViewAdapter(modelsList);
                listView.setAdapter(listViewAdapter);
            }
        });

This is the layout

<androidx.coordinatorlayout.widget.CoordinatorLayout
    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:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|enterAlways"
            app:menu="@menu/menu_main"
            app:title="@string/app_name" />
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:layout_scrollFlags="scroll|enterAlways"/>
        </com.google.android.material.appbar.AppBarLayout>
        <ListView
            android:id="@+id/listView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/corners_small_value"
            android:layout_marginLeft="@dimen/corners_small_value"
            android:layout_marginRight="@dimen/corners_small_value"
            android:visibility="invisible">
        </ListView>
        <View
            android:id="@+id/toolbar_shadow"
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:layout_below="@+id/toolbar"
            android:background="@drawable/toolbar_shadow" />
        <RelativeLayout
            android:id="@+id/view_search"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#50000000"
            android:clickable="true"
            android:elevation="10dp"
            android:visibility="invisible">
            <ProgressBar
                android:id="@+id/marker_progress"
                style="?android:attr/progressBarStyle"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerInParent="true"
                android:indeterminate="true"
                android:visibility="gone" />
        </RelativeLayout>
        <ListView
            android:id="@+id/listContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff"
            android:clipToPadding="false"
            android:divider="#fff"
            android:paddingTop="56dp"
            android:visibility="gone" />
        <androidx.cardview.widget.CardView
            android:id="@+id/card_search"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="4dp"
            app:layout_anchorGravity="top"
            app:cardElevation="200dp"
            app:cardCornerRadius="2dp">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:id="@+id/linearLayout_search"
                    android:layout_width="match_parent"
                    android:layout_height="48dp">
                    <ImageView
                        android:id="@+id/image_search_back"
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:background="?android:attr/selectableItemBackground"
                        android:clickable="true"
                        android:padding="12dp"
                        android:src="@drawable/ic_arrow_back" />
                    <EditText
                        android:id="@+id/edit_text_search"
                        android:layout_width="120dp"
                        android:padding="4dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:background="@drawable/rounded_editetext"
                        android:focusable="true"
                        android:gravity="center_vertical"
                        android:hint="@string/search_area_data"
                        android:imeOptions="actionSearch"
                        android:inputType="textCapWords"
                        android:maxLines="1"
                        android:paddingLeft="12dp"
                        android:paddingRight="8dp" />
                </LinearLayout>
                <View
                    android:id="@+id/line_divider"
                    android:layout_width="match_parent"
                    android:layout_height=".5dp"
                    android:layout_below="@+id/linearLayout_search"
                    android:background="#eee" />
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:paddingTop="2dp"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_below="@+id/line_divider"
                    android:divider="#FFFFFF" />
            </RelativeLayout>
        </androidx.cardview.widget.CardView>
        <TextView
            android:id="@+id/txtNoResultsFound"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:visibility="gone"
            android:padding="@dimen/activity_horizontal_margin"
            android:text="@string/no_results_found"/>
        <androidx.viewpager.widget.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:background="@color/white"
            android:src="@drawable/ic_baseline_add_24"
            android:layout_margin="@dimen/fab_margin"
            android:contentDescription="@string/report_your_case"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

This is the problem E/AndroidRuntime: FATAL EXCEPTION: main Process: com.doopisoft.dspots, PID: 8605 java.lang.RuntimeException: Unable to start activity ComponentInfo{.MainActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class com.google.android.material.appbar.MaterialToolbar at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3013) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3148) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6819) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912) Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class com.google.android.material.appbar.MaterialToolbar Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.google.android.material.appbar.MaterialToolbar Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:807) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:880) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:841) at android.view.LayoutInflater.rInflate(LayoutInflater.java:883) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:841) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) at com.doopisoft.dspots.MainActivity.onCreate(MainActivity.java:65) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2990) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3148) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6819) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912) Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 29: TypedValue{t=0x2/d=0x7f0400c6 a=6} at android.content.res.TypedArray.getColorStateList(TypedArray.java:546) E/AndroidRuntime: at androidx.appcompat.widget.TintTypedArray.getColorStateList(TintTypedArray.java:184) at androidx.appcompat.widget.Toolbar.(Toolbar.java:341) at com.google.android.material.appbar.MaterialToolbar.(MaterialToolbar.java:78) at com.google.android.material.appbar.MaterialToolbar.(MaterialToolbar.java:74) I would really appreciate if you help me out. Where could be my problem? Thanks in advance

1
stackoverflow.com/help/how-to-ask please go through this link as you are new to the communityAnurag Sharma

1 Answers

0
votes

In your layout the material Toolbar's height should be wrap_content.

 <com.google.android.material.appbar.MaterialToolbar
     android:layout_width="match_parent"
     android:layout_height="wrap_content"/>