在其他活动中的显示导航抽屉上的错误?

问题描述:

我使用本教程制作导航抽屉:http://www.tutecentral.com/android-custom-navigation-drawer/在其他活动中的显示导航抽屉上的错误?

所以现在我想添加我的导航到其他活动,但不幸的是我不能。 我也遵循这样的:How to Display Navigation Drawer in all activities?

,并做到这一点我的第二个活动,但它有一些错误:

package com.example.uniapp; 

import java.util.ArrayList; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.support.v4.app.FragmentTransaction; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class ShowAll extends Description { 
MyDatabase MyDataBase; 
SQLiteDatabase mydb; 
TextView title,content; 
ImageView image; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View contentView = inflater.inflate(R.layout.showall, null, false); 
    mDrawerLayout.addView(contentView, 0); //null pointer error 
    } 
} 

你有什么建议吗?

+0

什么错误...? –

+0

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.uniapp/com.example.uniapp.ShowAll}:java.lang.NullPointerException 09-07 00:50:57.765:E/AndroidRuntime(11515): \t at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404) –

这意味着您的drawerLayout为null。这可能是因为它找不到它。如果你想让你的navigationdrawer进行多个活动,你还需要为drawerLayout添加其所有xml文件的活动。

+0

谢谢。但你是什么意思“添加drawerLayout的所有活动的XML文件”我怎么能添加一个布局在XML文件? –

+0

看看这个回答http://*.com/a/25254794/2564847 –

+0

我只是做他们所说的。你在那个网页上点什么? PLZ解释更多谢谢 –