不幸的是我的应用程序有Stopped错误

时间:2014-09-09 06:38:39

标签: android actionbarsherlock

我使用Sherlock Library创建了一个幻灯片菜单 当我想用滑动菜单启动片段后登录滑动菜单没有开始给出不幸的错误..当我调试我的调试器停在

    rlProfile.setOnClickListener(this);   at this line 

这是我的Log Cat错误

09-09 12:04:23.662: E/AndroidRuntime(6560): FATAL EXCEPTION: main
09-09 12:04:23.662: E/AndroidRuntime(6560): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phonebook/com.example.phonebook.SlidingMenuDrawer}: java.lang.NullPointerException
09-09 12:04:23.662: E/AndroidRuntime(6560): Caused by: java.lang.NullPointerException
09-09 12:04:23.662: E/AndroidRuntime(6560):     at com.example.phonebook.SlidingMenuDrawer.initMenu(SlidingMenuDrawer.java:140)
09-09 12:04:23.662: E/AndroidRuntime(6560):     at com.example.phonebook.SlidingMenuDrawer.onCreate(SlidingMenuDrawer.java:83)
09-09 12:04:23.662: E/AndroidRuntime(6560):     at android.app.Activity.performCreate(Activity.java:5008)
09-09 12:04:23.662: E/AndroidRuntime(6560):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-09 12:04:23.662: E/AndroidRuntime(6560):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)

这是我的代码

SlidingDrawer

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    initMenu();

    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, // host Activity
            mDrawerLayout, // DrawerLayout object
            R.drawable.ic_drawer, // nav drawer image to replace 'Up' image
            R.string.drawer_open, // "open drawer" description for accessibility
            R.string.drawer_close // "close drawer" description for accessibility
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        switchFragment(new Category());
        setSelected(rlHome);
        mDrawerLayout.closeDrawer(mDrawerList); // Keep drawer open by default
    }

}

private void initMenu() {
    UserModel user=(UserModel) getIntent().getSerializableExtra("User");

    rlProfile = (RelativeLayout) findViewById(R.id.rlProfile);
    rlHome = (RelativeLayout) findViewById(R.id.rlHome);
    rlUploads = (RelativeLayout) findViewById(R.id.rlUploads);
    rlSubscriptions = (RelativeLayout) findViewById(R.id.rlSubscriptions);
    rlFav = (RelativeLayout) findViewById(R.id.rlFav);
    rlPlaylists = (RelativeLayout) findViewById(R.id.rlPlaylists);
    rlHistory = (RelativeLayout) findViewById(R.id.rlHistory);

    ivMenuFacebook = (ImageView) findViewById(R.id.ivMenuFacebook);
    ivMenuTwitter = (ImageView) findViewById(R.id.ivMenuTwitter);
    ivMenuShare = (ImageView) findViewById(R.id.ivMenuShare);

    rlProfile.setOnClickListener(this);
    rlHome.setOnClickListener(this);
    rlUploads.setOnClickListener(this);
    rlSubscriptions.setOnClickListener(this);
    rlFav.setOnClickListener(this);
    rlPlaylists.setOnClickListener(this);
    rlHistory.setOnClickListener(this);

    ivMenuFacebook.setOnClickListener(this);
    ivMenuTwitter.setOnClickListener(this);
    ivMenuShare.setOnClickListener(this);
    imageloader= new ImageLoaderThumbnail(getApplicationContext());
    String Img_url=user.getUser_Image();

          ImageView i=(ImageView)findViewById(R.id.avatar);
          imageloader.DisplayImage(Img_url, i);
    /*      Picasso.with(getApplicationContext())
        .load(Img_url).transform(new RoundedImageView()).into(i);*/
          String Username=user.getUser_Full_Name();
          TextView username=(TextView)findViewById(R.id.title);
          username.setText(Username);


}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            mDrawerLayout.openDrawer(mDrawerList);
        }
    }
    return true;

}

@Override
public void onClick(View v) {

    // update the main content by replacing fragments
    Fragment newContent = new Category();
    Bundle bundle = new Bundle();

    if (v.getId() == R.id.rlProfile) {
        // PROFILE
        newContent = new Welcome();
        bundle.putString(CUR_PAGE_TITLE, "Profile");
        setTitle("Profile");
        setSelected(rlProfile);
    } else if (v.getId() == R.id.rlHome) {
        // HOME
        setTitle("Home");
        bundle.putString(CUR_PAGE_TITLE, "Home");
        setSelected(rlHome);
    } else if (v.getId() == R.id.rlUploads) {
        // UPLOADS
        setTitle("Uploads");
        bundle.putString(CUR_PAGE_TITLE, "Uploads");
        setSelected(rlUploads);
    } else if (v.getId() == R.id.rlSubscriptions) {
        // Subscriptions
        newContent = new MeetPeople();
        setTitle("Meet People");
        bundle.putString(CUR_PAGE_TITLE, "Meet People");
        setSelected(rlSubscriptions);
    } else if (v.getId() == R.id.rlPlaylists) {
        // PLAYLISTS
        newContent = new FriendsActivity();
        setTitle("Friends");
        bundle.putString(CUR_PAGE_TITLE, "Friends");
        setSelected(rlPlaylists);
    } else if (v.getId() == R.id.rlHistory) {
        // HISTORY
        newContent = new SettingProfile();
        setTitle("History");
        bundle.putString(CUR_PAGE_TITLE, "History");
        setSelected(rlHistory);
    } else if (v.getId() == R.id.rlFav) {
        // FAVOURITES
        setTitle("Favourites");
        bundle.putString(CUR_PAGE_TITLE, "Favourites");
        setSelected(rlFav);
    }

    // SHARE
    else if (v.getId() == R.id.ivMenuFacebook) {
        // FACEBOOK
        Toast.makeText(this, "Facebook pressed!", Toast.LENGTH_SHORT).show();
    } else if (v.getId() == R.id.ivMenuTwitter) {
        // TWITTER
        Toast.makeText(this, "Twitter pressed!", Toast.LENGTH_SHORT).show();
    } else if (v.getId() == R.id.ivMenuShare) {
        // SHARE
        Toast.makeText(this, "Share pressed!", Toast.LENGTH_SHORT).show();
    }

    if (newContent != null) {
        newContent.setArguments(bundle);
        switchFragment(newContent);
    }

}

0 个答案:

没有答案