我listview
和employeename
radiobutton
。我使用setonclicklistner
作为radioButton
,但我得到了nullpointer异常,app崩溃了。有人可以帮我解决这个问题吗?
delivery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater1 = (LayoutInflater) ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v1 = inflater1.inflate(R.layout.activity_employees_list_for_pop_up, null);
RadioButton employeechecked = (RadioButton) v1.findViewById(R.id.employeeChecked);
final Button ok = (Button) v1.findViewById(R.id.do_ok);
Button cancle = (Button) v1.findViewById(R.id.do_cancle);
ok.setEnabled(false);
listView = (ListView) v1.findViewById(R.id.employeePopUpList);
employeePopUpAdapter = new EmployeePopUpAdapter(ct, employeeIdNameBeans);
//enable ok button if listitem is checked
employeechecked.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos=listView.getCheckedItemPosition();
if (pos > -1)
{
ok.setEnabled(true);
}
else if (pos <= -1)
{
ok.setEnabled(false);
}
}
});
错误 当我点击textview
时,我得到了nullpointer异常 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.jithendra.businessstorestart.adapters.DeliveryOrdersListAdapter$3.onClick(DeliveryOrdersListAdapter.java:300)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这是布局文件
<LinearLayout
android:id="@+id/lv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/employeeId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/loading"
android:textColor="@color/TextcolorforBlack"
android:textSize="20dp" />
<TextView
android:id="@+id/empFullName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/loading"
android:textColor="@color/TextcolorforBlack"
android:textSize="20dp" />
<RadioButton
android:id="@+id/employeeChecked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/TextcolorforBlack"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_weight="0"
android:background="@color/TextcolorforBlack" />
</LinearLayout>
这是我在listview中对它进行充气的列表。在此列表视图中,我有radiobutton
。如果radiobutton检查我需要启用按钮
答案 0 :(得分:0)
employeechecked按钮视图似乎为null,
RadioButton employeechecked = (RadioButton) v1.findViewById(R.id.employeeChecked);
检查您夸大的布局R.layout.activity_employees_list_for_pop_up