为什么它一直抛出这个指针异常 - 我假设自定义布局没有问题。有人会告诉我,我在onCreate方法中定义的textview有什么问题。是的,正在阅读文本文件中的Recall按钮并调用分析数据的方法,但我正在努力同时在textview中显示结果。这有什么不对?我阻止了用户界面吗?提前谢谢你,我知道..所以不要告诉我Nullpointer是一个反复的问题。最好
TextView Peaks_num;
@overide
onCreate(){
.....
.....
//Read data.
Recall = (Button) findViewById(R.id.Recall);
Recall.setOnClickListener(new View.OnClickListener() {
StringBuilder stringBuilder = new StringBuilder();
String line = null;
@Override
public void onClick(View v) {
List<Integer> List_Of_Peaks = findPeaks(String_TO_List);
Dialog mdialog = new Dialog(MainActivity.this);
mdialog.setTitle("MyDialog");
mdialog.setContentView(R.layout.customdialog);
mdialog.show();
Peaks_num = (TextView) findViewById(R.id.Peak_Num);
Peaks_num.setText(String.valueOf(List_Of_Peaks));
}
});
//my custom layout that should to be for the textview inside the dialog.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="@+id/Peak_Num"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="1.7dp"
android:background="@drawable/back"
android:text="Peaks"
android:textColor="#040307" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/textView_Peaks_index"
android:id="@+id/text_Index"
android:layout_weight="1" />
</LinearLayout>