2017-05-17 8 views
0

ご挨拶フラグメント - ナビゲーションドロワ - アプリの停止エラー

私はカメラのテキストをクリックすると、「アプリケーションが停止しました」というエラーが表示されます。どのように修正することができますか?

MaingActivity.java

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 
     CameraFragment cameraFragment = new CameraFragment(); 
     FragmentManager manager= getSupportFragmentManager(); 
     manager.beginTransaction().replace(
       R.id.relativelayout_for_fragment, 
       cameraFragment, 
       cameraFragment.getTag() 
     ).commit(); 

    } else if (id == R.id.nav_gallery) { 
     Toast.makeText(this,"Gallary",Toast.LENGTH_SHORT).show(); 
    } else if (id == R.id.nav_gallery) { 

    } 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; 
} 

答えて

0
I have found it 
Select contant_main.xml => click on icon refer Constrains 

The code will be as the following 

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.shakeralmoosa.nav1.MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    android:id="@+id/mainLayout"> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     tools:layout_constraintTop_creator="1" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintBottom_creator="1" 
     android:layout_marginStart="5dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginEnd="5dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginTop="4dp" 
     tools:layout_constraintLeft_creator="1" 
     android:layout_marginBottom="4dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp"> 


    </RelativeLayout> 

</android.support.constraint.ConstraintLayout> 
関連する問題