0

I am trying to implement an up button in my toolbar to redirect to the previous activity. The up button coded in the Dashboard.java. When I click the up button, it will display the Homepage.

Android Manifest.xml

    <activity android:name="fyp.ui_activities.Dashboard"
        android:parentActivityName="fyp.ui_activities.Homepage">
        <meta-data android:name="android.support.PARENT_ACTIVITY"
            android:value="fyp.ui_activities.Homepage"/>
    </activity>

    

For Themes.xml, I am using NoActionBar

Dashboard.xml

<androidx.drawerlayout.widget.DrawerLayout
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"
android:id="@+id/drawer_layout"
tools:context=".Dashboard">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toolbar"
        app:title="@string/dashboardheader"
        app:titleTextColor="@color/font_Primary">
    </androidx.appcompat.widget.Toolbar>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>

Dashboard.java

public class Dashboard extends AppCompatActivity {
DrawerLayout drawerLayout;
ActionBarDrawerToggle actionBarDrawerToggle;

TextView speed,rpm,test;
int i,j;
Random rand = new Random();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard);
    setUpToolbar();
    print();
    createThread();
}

public void setUpToolbar(){
    drawerLayout = findViewById(R.id.drawer_layout);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    actionBarDrawerToggle  = new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.dashboardheader,R.string.dashboardheader);
}

}

Error

java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
  • what exactly is your question ? – a_local_nobody Jan 22 '21 at 07:48
  • I believe you also need drawer items (with appropriate layout gravity) in your drawerlayout and not just the content layout as you have now. – laalto Jan 22 '21 at 07:50
  • your error is not nullPointerException but "java.lang.IllegalArgumentException: No drawer view found with gravity LEFT". Have a look at https://stackoverflow.com/questions/27350136/android-drawerlayout-no-drawer-view-found-with-gravity . Your layout needs two children, the first is the content of the view, the second is the content of the drawerLayout which need a gravity, start is the most common. you miss a second view representing the drawerLayout. – SebastienRieu Jan 22 '21 at 07:51

0 Answers0