Мое приложение разбивается с навигационным ящиком

Я разрабатываю приложение, в котором у меня есть одно время открытие действия (с именем «logIn») с последующим моим main_activity. С помощью некоторых блогов я пытался реализовать навигационный ящик в моем main_activity (названный «чаты»).

мои чаты.Java-файл :

public class Chats extends AppCompatActivity {

String TITLES[] = {"Home","Events","Mail","Shop","Travel"};
int ICONS[] = {R.drawable.ic_action_alarms,R.drawable.ic_action_alarms,R.drawable.ic_action_alarms,R.drawable.ic_action_alarms,R.drawable.ic_action_alarms};

String NAME = "Karan Nagpal";
String EMAIL = "nagpalkaran95@gmail.com";
int PROFILE = R.drawable.ic_action_alarms;

private Toolbar toolbar;                              // Declaring the Toolbar Object

RecyclerView mRecyclerView;                           // Declaring RecyclerView
RecyclerView.Adapter mAdapter;                        // Declaring Adapter For Recycler View
RecyclerView.LayoutManager mLayoutManager;            // Declaring Layout Manager as a linear layout manager
DrawerLayout Drawer;                                  // Declaring DrawerLayout

ActionBarDrawerToggle mDrawerToggle;


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

    Boolean isFirstTime;
    SharedPreferences app_preferences = getSharedPreferences("mainuser",MODE_PRIVATE);
    SharedPreferences.Editor editor = app_preferences.edit();

    isFirstTime = app_preferences.getBoolean("isFirstTime", true);

    if (isFirstTime) {
        Intent i = new Intent(this, logIn.class);
        startActivity(i);
        editor.putBoolean("isFirstTime", false);
        editor.commit();
    }
    else{
        setContentView(R.layout.activity_chats);
        final String username = app_preferences.getString("username", null);
        if(username==null){
            Intent i = new Intent(this, logIn.class);
            startActivity(i);
            editor.putBoolean("isFirstTime", false);
            editor.commit();
        }
        TextView main_user = (TextView) findViewById(R.id.main_user);
        main_user.setText(username);

    }

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

    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size

    mAdapter = new MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE);       

    mRecyclerView.setAdapter(mAdapter);                              

    mLayoutManager = new LinearLayoutManager(this);                 

    mRecyclerView.setLayoutManager(mLayoutManager);                 


    Drawer = (DrawerLayout) findViewById(R.id.drawer_layout);        
    mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.openDrawer,R.string.closeDrawer){

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }
    };

    Drawer.setDrawerListener(mDrawerToggle); 
    mDrawerToggle.syncState();               
   }
}

Ошибка журнала :

  10-02 23:53:31.484 2258-2334/com.nagpal.karan.radarchat I/OpenGLRenderer: Initialized EGL, version 1.4
  10-02 23:53:31.503 2258-2334/com.nagpal.karan.radarchat D/OpenGLRenderer: Enabling debug mode 0
  10-02 23:53:31.516 2258-2258/com.nagpal.karan.radarchat E/Xposed: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.view.View.getContext()' on a null object reference
        at tw.fatminmin.xposed.minminguard.blocker.NameBlocking.clearAdViewInLayout(NameBlocking.java:87)
        at tw.fatminmin.xposed.minminguard.blocker.NameBlocking.afterHookedMethod(NameBlocking.java:150)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:754)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:740)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at com.nagpal.karan.radarchat.MyAdapter.onCreateViewHolder(MyAdapter.java:98)
        at com.nagpal.karan.radarchat.MyAdapter.onCreateViewHolder(MyAdapter.java:11)
        at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5836)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5060)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
        at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1221)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2097)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1069)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5915)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
        at android.view.Choreographer.doCallbacks(Choreographer.java:580)
        at android.view.Choreographer.doFrame(Choreographer.java:550)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessag
  10-02 23:53:31.517 2258-2258/com.nagpal.karan.radarchat E/Xposed: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.view.View.getContext()' on a null object reference
        at tw.fatminmin.xposed.minminguard.blocker.NameBlocking.clearAdViewInLayout(NameBlocking.java:87)
        at tw.fatminmin.xposed.minminguard.blocker.NameBlocking.afterHookedMethod(NameBlocking.java:150)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:754)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at com.nagpal.karan.radarchat.MyAdapter.onCreateViewHolder(MyAdapter.java:98)
        at com.nagpal.karan.radarchat.MyAdapter.onCreateViewHolder(MyAdapter.java:11)
        at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5836)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5060)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
        at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1221)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2097)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1069)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5915)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
        at android.view.Choreographer.doCallbacks(Choreographer.java:580)
        at android.view.Choreographer.doFrame(Choreographer.java:550)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:139)
        at android.app.ActivityThread.main(ActivityThread.java:5298)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndAr
  10-02 23:53:31.517 2258-2258/com.nagpal.karan.radarchat D/AndroidRuntime: Shutting down VM
  10-02 23:53:31.520 2258-2258/com.nagpal.karan.radarchat E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.nagpal.karan.radarchat, PID: 2258
  android.view.InflateException: Binary XML file line #43: Error inflating class de.hdodenhof.circleimageview.CircleImageView
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:740)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:740)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at com.nagpal.karan.radarchat.MyAdapter.onCreateViewHolder(MyAdapter.java:98)
        at com.nagpal.karan.radarchat.MyAdapter.onCreateViewHolder(MyAdapter.java:11)
        at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5836)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5060)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
        at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1221)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
        at android.view.View.layout(View.java:15715)
        at android.view.ViewGroup.layout(ViewGroup.java:5046)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2097)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1069)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5915)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
        at android.view.Choreographer.doCallbacks(Choreographer.java:580)
        at android.view.Choreographer.doFrame(Choreographer.java:550)
        at android.view.Choreographer$FrameD
  10-02 23:53:31.521 2258-2258/com.nagpal.karan.radarchat D/AppTracker: App Event: crash
  10-02 23:53:31.870 2258-2258/com.nagpal.karan.radarchat I/Process: Sending signal. PID: 2258 SIG: 9

XML-файл :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
android_layout_width="match_parent"
android_layout_height="178dp"
android_background="@drawable/ic_action_alarms"
android_orientation="vertical"
android_weightSum="1">

<LinearLayout
    android_layout_width="match_parent"
    android_layout_height="56dp"
    android_orientation="vertical"
    android_layout_alignParentBottom="true"
    android_layout_alignParentLeft="true"
    android_layout_alignParentStart="true">
    <TextView
        android_id="@+id/name"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginLeft="16dp"
        android_textColor="#ffffff"
        android_text="Akash Bangad"
        android_textSize="14sp"
        android_textStyle="bold"
        />
    <TextView
        android_id="@+id/email"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_textColor="#ffffff"
        android_layout_marginLeft="16dp"
        android_layout_marginTop="5dp"
        android_text="akash.bangad93@gmail.com"
        android_textSize="14sp"
        android_textStyle="normal"/>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
    android_layout_width="70dp"
    android_layout_height="70dp"
    android_src="@drawable/ic_action_alarms"
    android_layout_marginLeft="16dp"
    android_layout_marginTop="38dp"
    android_id="@+id/circleView"
    />

1 ответ

  1. setContentView() вызывается только в вашей elseчасти оператора if-else. Это означает, что если ваша логика входит в ifчасть, она начнет новую деятельность, как это сделал u, но она будет продолжать идти, так как вы не закончите работу.

    После if-else, вы делаете findViewById(). Это не может работать, если нет никакого представления, прикрепленного к действию.

    Просто позвоните this.finish()в ifраздел

    ИЛИ

    просто раскомментируйте setContentView(R.layout.activity_chats);сверху и снимите его с elseдетали.

    Рекомендую 2-й вариант. Если вы так или иначе собираетесь начать новое действие, то это не будет иметь значения, если вы сначала прикрепите представление.

    РЕДАКТИРОВАТЬ:

    Заменить это:

    <de.hdodenhof.circleimageview.CircleImageView
        android_layout_width="70dp"
        android_layout_height="70dp"
        android_src="@drawable/ic_action_alarms"
        android_layout_marginLeft="16dp"
        android_layout_marginTop="38dp"
        android_id="@+id/circleView" />
    

    С этим:

    <de.hdodenhof.circleimageview.CircleImageView
        
        android_id="@+id/circleView"
        android_layout_width="70dp"
        android_layout_height="70dp"
        android_src="@drawable/ic_action_alarms"
        android_layout_marginLeft="16dp"
        android_layout_marginTop="38dp" />