Я делаю программу изучения языка. То, над чем я работаю, - это тест для каждой группы слов.
Нет ошибки компиляции; однако, согласно моему logcat, на моем адаптере есть нулевое исключение. Я не уверен, почему это происходит.
Мой адаптер
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(this.layout, parent, false);
holder.answer = (EditText)convertView.findViewById(R.id.answer);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.ref = position;
final EditText answer = (EditText)convertView.findViewById(R.id.answer);
final Test listViewItem = TestList.get(position);
holder.answer.setText(listViewItem.getAns());
if(listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.row, parent, false);
Test currenttest = TestList.get(position);
TextView Qunum = (TextView) listItem.findViewById(R.id.Qnum);
Qunum.setText(currenttest.getQnum());
TextView Kore = (TextView) listItem.findViewById(R.id.Korean1);
Kore.setText(currenttest.getK());
TextView Prono = (TextView) listItem.findViewById(R.id.Pronounciation);
Prono.setText(currenttest.getPron());
return listItem;
}
Деятельность, которая требует намерения
getScore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int i=0;i<20;i++){
View view=listview.getChildAt(i);
EditText editText=view.findViewById(R.id.answer);
String string = editText.getText().toString();
inputans.add(string);
}
count = 0;
for(int x = 0; x < 20; x++){
if(answers.get(x) == inputans.get(x)){
count++;
}
}
Intent intent = new Intent(numbertest.this, dicselect.class);
intent.putExtra("score", count);
if(count<10){
intent.putExtra("message", "Work Harder !!");
startActivityForResult(intent, 1);
}
else if(count<=15){
intent.putExtra("message", "Great !!");
startActivityForResult(intent, 1);
}
else{
intent.putExtra("message", "Well Done !!");
startActivityForResult(intent, 1);
}
startActivity(intent);
}
});
XML-код для элемента моего пользовательского списка
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="390dp"
android:layout_height="50dp"
android:orientation = "horizontal">
<TextView
android:id="@+id/Qnum"
android:text=""
android:layout_width="40dp"
android:layout_height="40dp"
android:textColor="#000000"
android:textSize="20dp"
android:layout_marginLeft="4dp"
android:layout_marginTop = "4dp"
android:layout_gravity="center"/>
<TextView
android:id="@+id/Korean1"
android:text=""
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:textSize = "20dp"/>
<TextView
android:text=""
android:id="@+id/Pronounciation"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_gravity = "center"
android:layout_marginLeft = "4dp"
android:textSize = "20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="390dp"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_marginLeft="2dp"
android:text = "Answer: "
android:layout_gravity="center"
android:textSize = "25dp"
android:textColor = "#000000"
/>
<EditText
android:id="@+id/answer"
android:layout_width="270dp"
android:layout_height="40dp"
android:textSize="20dp"
android:layout_marginLeft="5dp"
android:layout_gravity="center"
/>
</LinearLayout>
LogCat
java.lang.NullPointerException: попытка вызвать виртуальный метод «void android.widget.TextView.setText (java.lang.CharSequence)» для ссылки на пустой объект
на com.example.rkdtm.koreanlearner.TestAdapter.getView (TestAdapter.java:73)
на android.widget.AbsListView.obtainView (AbsListView.java:2366)
atroid.widget.ListView.makeAndAddView (ListView.java:2052)