Navigation Drawer with tabs stops when I run it

96 views Asked by At

Im trying to develop a Navigation drawer with 2 tabs. I also created 2 Fragments for each tabs. But when I run the app it stops.

This is the main activity

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {


    private FragmentTabHost mTabHost;

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

        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);

        mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);

        mTabHost.addTab(
                mTabHost.newTabSpec("tab1").setIndicator("Tab 1", null),
                MapsFragment.class, null);

        mTabHost.addTab(
                mTabHost.newTabSpec("tab1").setIndicator("Tab 1", null),
                RecomendadosFragment.class, null);


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





        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        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 = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @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, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

This is the xml Content of the Navigation Drawer

<?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:id="@+id/content_main"
    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="com.example.abdiel.culinarioproyect.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <TabHost
        android:layout_width="200dip"
        android:layout_height="300dip"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:id="@+id/tabhost">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                </LinearLayout>

            </FrameLayout>
        </LinearLayout>
    </TabHost>
</RelativeLayout>

This is the logcat

12-23 00:24:07.972 4539-4539/? D/dalvikvm: Zygote::ForkAndSpecialize : 0
12-23 00:24:07.974 4539-4539/? E/cutils: to chown(/mnt/shell/emulated/0, 0, 0)
12-23 00:24:07.975 4539-4539/? E/cutils: to chown(/mnt/shell/emulated/obb, 0, 0)
12-23 00:24:07.975 4539-4539/? E/cutils: to chown(/storage/emulated/0/Android, 0, 0)
12-23 00:24:07.975 4539-4539/? E/cutils: to chown(/storage/emulated/0/Android/obb, 0, 0)
12-23 00:24:07.976 4539-4539/? D/dalvikvm: zygote get new systemTid : 4539
12-23 00:24:07.976 4539-4539/? D/dalvikvm: Late-enabling CheckJNI
12-23 00:24:08.004 4539-4539/? D/jdwp: prepping for JDWP over ADB
12-23 00:24:08.004 4539-4539/? D/jdwp: ADB transport startup
12-23 00:24:08.005 4539-4545/? D/dalvikvm: Elevating priority from 0 to -8
12-23 00:24:08.026 4539-4546/? D/jdwp: JDWP: thread running
12-23 00:24:08.026 4539-4546/? D/jdwp: acceptConnection
12-23 00:24:08.027 4539-4546/? D/jdwp: trying to receive file descriptor from ADB
12-23 00:24:08.027 4539-4539/? D/dalvikvm: zygote get thread init done
12-23 00:24:08.037 4539-4546/? D/jdwp: received file descriptor 35 from ADB
12-23 00:24:08.042 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.044 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.044 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000192, flags=0x0, dataLen=0x8
12-23 00:24:08.047 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.047 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x17, id=0x40000193, flags=0x0, dataLen=0xC
12-23 00:24:08.048 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.048 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000194, flags=0x0, dataLen=0x8
12-23 00:24:08.050 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.050 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000195, flags=0x0, dataLen=0x8
12-23 00:24:08.052 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.052 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x40000196, flags=0x0, dataLen=0x9
12-23 00:24:08.065 4539-4539/? D/jdwp: sendBufferedRequest : len=0x3D
12-23 00:24:08.119 4539-4539/? D/jdwp: sendBufferedRequest : len=0x61
12-23 00:24:08.125 4539-4539/? W/asset: AssetManager-->addDefaultAssets CIP path not exsit!
12-23 00:24:08.210 4539-4539/? W/SystemTheme/Resources: createSystemThemeIfNeeded
12-23 00:24:08.210 4539-4539/? I/SystemThemeResource: SystemThemeResource: set to default lenovo theme
12-23 00:24:08.216 4539-4539/? I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
12-23 00:24:08.216 4539-4539/? W/dalvikvm: VFY: unable to resolve interface method 19515: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
12-23 00:24:08.216 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-23 00:24:08.217 4539-4539/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
12-23 00:24:08.217 4539-4539/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
12-23 00:24:08.217 4539-4539/? W/dalvikvm: VFY: unable to resolve interface method 19517: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
12-23 00:24:08.217 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-23 00:24:08.217 4539-4539/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
12-23 00:24:08.217 4539-4539/? W/dalvikvm: VFY: unable to resolve interface method 19521: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
12-23 00:24:08.217 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-23 00:24:08.219 4539-4539/? I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
12-23 00:24:08.219 4539-4539/? W/dalvikvm: VFY: unable to resolve virtual method 475: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
12-23 00:24:08.219 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-23 00:24:08.220 4539-4539/? I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
12-23 00:24:08.220 4539-4539/? W/dalvikvm: VFY: unable to resolve virtual method 497: Landroid/content/res/TypedArray;.getType (I)I
12-23 00:24:08.220 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
12-23 00:24:08.235 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.235 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x40000197, flags=0x0, dataLen=0x9
12-23 00:24:08.235 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.235 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x40000198, flags=0x0, dataLen=0x9
12-23 00:24:08.235 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.235 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x40000199, flags=0x0, dataLen=0x9
12-23 00:24:08.362 4539-4539/? I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
12-23 00:24:08.362 4539-4539/? W/dalvikvm: VFY: unable to resolve virtual method 290: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
12-23 00:24:08.362 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-23 00:24:08.369 4539-4539/? I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
12-23 00:24:08.369 4539-4539/? W/dalvikvm: VFY: unable to resolve direct method 20060: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
12-23 00:24:08.369 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
12-23 00:24:08.370 4539-4539/? I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
12-23 00:24:08.370 4539-4539/? W/dalvikvm: VFY: unable to resolve direct method 20060: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
12-23 00:24:08.370 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
12-23 00:24:08.443 4539-4539/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
12-23 00:24:08.443 4539-4539/? W/dalvikvm: VFY: unable to resolve instanceof 141 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
12-23 00:24:08.443 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
12-23 00:24:08.574 4539-4539/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
12-23 00:24:08.574 4539-4539/? W/dalvikvm: VFY: unable to resolve virtual method 438: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
12-23 00:24:08.574 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-23 00:24:08.575 4539-4539/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
12-23 00:24:08.575 4539-4539/? W/dalvikvm: VFY: unable to resolve virtual method 440: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
12-23 00:24:08.575 4539-4539/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-23 00:24:08.593 4539-4539/? D/AndroidRuntime: Shutting down VM
12-23 00:24:08.593 4539-4539/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x420369a8)
12-23 00:24:08.688 4539-4546/? D/jdwp: processIncoming
12-23 00:24:08.688 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000019A, flags=0x0, dataLen=0x9
12-23 00:24:08.688 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
12-23 00:24:09.190 4539-4546/? D/jdwp: processIncoming
12-23 00:24:09.190 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000019B, flags=0x0, dataLen=0x9
12-23 00:24:09.190 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
12-23 00:24:09.689 4539-4546/? D/jdwp: processIncoming
12-23 00:24:09.689 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000019C, flags=0x0, dataLen=0x9
12-23 00:24:09.689 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
12-23 00:24:10.189 4539-4546/? D/jdwp: processIncoming
12-23 00:24:10.189 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000019D, flags=0x0, dataLen=0x9
12-23 00:24:10.190 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
12-23 00:24:10.689 4539-4546/? D/jdwp: processIncoming
12-23 00:24:10.689 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000019E, flags=0x0, dataLen=0x9
12-23 00:24:10.690 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
12-23 00:24:11.191 4539-4546/? D/jdwp: processIncoming
12-23 00:24:11.191 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x4000019F, flags=0x0, dataLen=0x9
12-23 00:24:11.191 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
12-23 00:24:11.692 4539-4546/? D/jdwp: processIncoming
12-23 00:24:11.692 4539-4546/? D/jdwp: handlePacket : cmd=0x1, cmdSet=0xC7, len=0x14, id=0x400001A0, flags=0x0, dataLen=0x9
12-23 00:24:11.692 4539-4546/? D/jdwp: sendBufferedRequest : len=0x34
0

There are 0 answers