0

I have imported the scanner control module in my app. I have also added the module dependency correctly. I can even access the classes of imported module. But the problem is, whenever I try to open that module (I have added that as in main app navigation drawer item) it looks like there is a problem with setContentView(R.layout.activity_active_scanner). I think that the main problem is in tablayout(or else in other xml parts).

The logcat is shown below:

Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 60
    at android.content.res.TypedArray.getColor(TypedArray.java:401)
    at android.support.design.widget.TabLayout.<init>(TabLayout.java:348)
    at android.support.design.widget.TabLayout.<init>(TabLayout.java:290)
    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.rInflate(LayoutInflater.java:809) 
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
    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:284) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
    at ****com.zebra.scannercontrol.app.activities.ActiveScannerActivity.onCreate(ActiveScannerActivity.java:79)**** 
    at android.app.Activity.performCreate(Activity.java:6092)  

and the code for activity_active_scanner is:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_activescanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home"
        app:menu="@menu/activity_home_drawer" />

</android.support.v4.widget.DrawerLayout>  

and below is the app_bar_active_scanner which I have included in activity_active_scanner:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
    tools:context="com.zebra.scannercontrol.app.activities.ActiveScannerActivity">

    <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" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="@integer/abc_max_action_buttons"
            app:tabBackground="@color/blue"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/yellow"
            app:tabMaxWidth="0dp"
            app:tabMode="fixed"
            app:tabTextAppearance="@style/AppTabTextAppearance"/>
    </android.support.design.widget.AppBarLayout>

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

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

and given below is the ActiveScannerActivity in which, I have declared/initialized and set the tablayout with view pager. You can ignore other codes (I think main problem is with tablayout).

public class ActiveScannerActivity extends BaseActivity implements  NavigationView.OnNavigationItemSelectedListener,
        ActionBar.TabListener,ScannerAppEngine.IScannerAppEngineDevEventsDelegate,ScannerAppEngine.IScannerAppEngineDevConnectionsDelegate{
    private ViewPager viewPager;
    ActiveScannerAdapter mAdapter;
    TabLayout tabLayout;
    private NavigationView navigationView;
    static int picklistMode;

    public boolean isPagerMotorAvailable() {
        return pagerMotorAvailable;
    }

    static boolean pagerMotorAvailable;
    private int scannerID;
    TextView barcodeCount;
    int iBarcodeCount;
    int  BARCODE_TAB = 1;
    int ADVANCED_TAB = 2;
    static MyAsyncTask cmdExecTask=null;
    Button btnFindScanner = null;
    static final int ENABLE_FIND_NEW_SCANNER =1;


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

        Configuration configuration = getResources().getConfiguration();

        if(configuration.orientation == Configuration.ORIENTATION_LANDSCAPE){
            if(configuration.smallestScreenWidthDp<Application.minScreenWidth){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }else{
            if(configuration.screenWidthDp<Application.minScreenWidth){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }



        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        addDevConnectionsDelegate(this);
        scannerID = getIntent().getIntExtra(Constants.SCANNER_ID, -1);
        BaseActivity.lastConnectedScannerID = scannerID;
        String scannerName = getIntent().getStringExtra(Constants.SCANNER_NAME);
        String address = getIntent().getStringExtra(Constants.SCANNER_ADDRESS);

        picklistMode = getIntent().getIntExtra(Constants.PICKLIST_MODE, 0);

        pagerMotorAvailable = getIntent().getBooleanExtra(Constants.PAGER_MOTOR_STATUS,false);

        Application.CurScannerId = scannerID;
        Application.CurScannerName = scannerName;
        Application.CurScannerAddress = address;
        // Initilization
        viewPager = (ViewPager) findViewById(R.id.activeScannerPager);

        mAdapter= new ActiveScannerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);

        tabLayout = (TabLayout) findViewById(R.id.tablayout);
        tabLayout.setupWithViewPager(viewPager);
Bhavik Mehta
  • 459
  • 1
  • 6
  • 13
  • could be similar to this question ? https://stackoverflow.com/questions/30595187/android-xml-runtimeexception-failed-to-resolve-attribute-at-index-6 – Yazan Aug 01 '17 at 12:26
  • Change the theme of your activity to `AppCompat` theme. – azizbekian Aug 01 '17 at 12:57
  • nope, it didn't worked @azizbekian. is there any to be needed in Theme.AppCompat? Right now, it like this – Bhavik Mehta Aug 02 '17 at 12:17
  • nope it is not the same issue @yazan. can you help me solve this issue? i think its the problem of style or problem with tablayout. – Bhavik Mehta Aug 03 '17 at 12:36

0 Answers0