我有一个名为“temp”的项目,我实现了一些类及其方法。
然后我创建了另一个名为“temp2”的项目,并包含了库“temp”,以便使用我在那里实现的类。
现在,如果我在“临时”项目中创建了一个类:
private SwipeListView swipeListView; // SwipeListView is a class declared in "temp2" project
private MyCustomAdapter adapter; // class MyCustomAdapter is a class in "temp" project
swipeListView = (SwipeListView) findViewById(R.id.example_lv_list);
adapter =new MyCustomAdapter(text,listImages);
swipeListView.setListenerAdaper(adapter);
adapter.someMethod(); //doesnt give me a nullpointerException
在类中SwipeListView
,我声明了方法setListenerAdaper(BaseAdpter)
和useAdapter()
:
private BaseAdapter listAdapter;
public void setListenerAdaper(BaseAdapter baseAdapter) {
listAdapter = baseAdapter;
}
public void tempmethod() {
useAdapter();
}
public void useAdapter() {
listAdapter.someMethod(); //NullPointerException
}
我想listAdapter
在类中使用变量SwipeListView
,但是每当我想在类中调用适配器的方法时SwipeListView
,我都会得到一个NullPonterException