我正在尝试在我的项目中使用Volley,我曾经从PHP中获取JSON数组编码并将其改编为.我遵循了此页面的教程:https://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/JsonArrayRequest()ListView我的应用程序崩溃了,下面是错误。2019-03-18 15:34:51.706 14999-14999/com.example.smartparkingapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.smartparkingapp, PID: 14999 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)' on a null object reference at com.example.smartparkingapp.adapter.CarListAdapter.getView(CarListAdapter.java:48) at android.widget.AbsListView.obtainView(AbsListView.java:3180) at android.widget.ListView.makeAndAddView(ListView.java:2197) at android.widget.ListView.fillDown(ListView.java:824) at android.widget.ListView.fillFromTop(ListView.java:885) at android.widget.ListView.layoutChildren(ListView.java:1924) at android.widget.AbsListView.onLayout(AbsListView.java:2952) at android.view.View.layout(View.java:21054) at android.view.ViewGroup.layout(ViewGroup.java:6440) at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:1915) at android.view.View.layout(View.java:21054) at android.view.ViewGroup.layout(ViewGroup.java:6440) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:21054) at android.view.ViewGroup.layout(ViewGroup.java:6440) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
1 回答
杨魅力
TA贡献1811条经验 获得超6个赞
您正在尝试在适配器中使用空值。将活动对象从调用活动传递到 CarListAdapter 构造函数中activity
类似的东西:在你的家庭碎片
carListAdapter = new CarListAdapter(this, carList, getActivity());
并在您的 CarListAdapter 中:
public class CarListAdapter extends BaseAdapter {
private Activity activity;
private Fragment fragment;
private LayoutInflater layoutInflater;
private List<Car> carItems;
public CarListAdapter(Fragment fragment, List<Car> carItems, Activity activity) {
this.fragment = fragment;
this.carItems = carItems;
this.activity = activity;
}
.....
这是根据您显示的错误
添加回答
举报
0/150
提交
取消