Navigation drawer app has stopped with fragments and JSON parsing

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 615 Views - Last Post: 05 August 2017 - 11:58 AM

#16 suhailpappu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 02-July 17

Re: Navigation drawer app has stopped with fragments and JSON parsing

Posted 05 August 2017 - 11:58 AM

View Postndc85430, on 05 August 2017 - 11:49 AM, said:

After reading the documentation for NullPointerException, what seems likely and what seems unlikely? Remember, too, that you also have the message from the exception that's printed out in the stack trace.

I've made some changes and now i am receiving this
08-06 00:26:40.142 8894-8894/? I/art: Late-enabling -Xcheck:jni
08-06 00:26:40.218 8894-8894/com.pappu5.navigation W/System: ClassLoader referenced unknown path: /data/app/com.pappu5.navigation-2/lib/arm
08-06 00:26:40.366 8894-8894/com.pappu5.navigation D/AndroidRuntime: Shutting down VM
08-06 00:26:40.367 8894-8894/com.pappu5.navigation E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: com.pappu5.navigation, PID: 8894
                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pappu5.navigation/com.pappu5.navigation.MainActivity}: java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
                                                                         at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                      Caused by: java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
                                                                         at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1660)
                                                                         at com.pappu5.navigation.MainActivity.displaySelectedScreen(MainActivity.java:127)
                                                                         at com.pappu5.navigation.MainActivity.onCreate(MainActivity.java:54)
                                                                         at android.app.Activity.performCreate(Activity.java:6672)
                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724) 
                                                                         at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                         at android.os.Looper.loop(Looper.java:154) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6123) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 



Changes in MainActivity (please check it out please)
package com.pappu5.navigation;

import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import static com.pappu5.navigation.R.id.pappuLayout;
import static com.pappu5.navigation.R.id.recyclerView;


public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener,GalleryFrag.OnFragmentInteractionListener {





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



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

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

        //add this line to display menu1 when the activity is loaded
        displaySelectedScreen(R.id.nav_gallery);
    }



    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.pappuLayout);
        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.

        displaySelectedScreen(item.getItemId());

        return true;
    }

    private void displaySelectedScreen(int itemId) {

        //creating fragment object
        Fragment fragment = null;

        //initializing the fragment object which is selected
        switch (itemId) {
            case R.id.nav_gallery:
                fragment = new GalleryFrag();
                break;
            /*case R.id.nav_menu2:
                fragment = new Menu2();
                break;
            case R.id.nav_menu3:
                fragment = new Menu3();
                break;*/
        }

        //replacing the fragment
        if (fragment != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.content_frame, fragment);
            ft.commit();
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(pappuLayout);
        drawer.closeDrawer(GravityCompat.START);
    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2