<分区>
我正在尝试制作第二个工具栏
,紧挨着我顶部栏中的工具栏。
基本上有一个 Button
,当按下它时,窗口中会弹出一个栏。
用户应该能够阅读栏上的内容并可以按下 Button
。
现在我正试图在那里获取文本。但这似乎不起作用。
.java 函数:(当按下某个按钮时调用,显示工具栏)
public void showDialogue() {
//Set popupscherm as view
View v = getLayoutInflater().inflate(R.layout.popupscherm,null);
AlertDialog.Builder adb = new AlertDialog.Builder(GraphActivity.this);
adb.setView(v);
// Find the toolbar view inside the activity layout
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("test"); //Here it gives the error
AlertDialog alert = adb.create();
alert.show();
popupscherm.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>
</LinearLayout>
错误:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setTitle(java.lang.CharSequence)' 在空对象引用上