「temp」という名前のプロジェクトがあり、いくつかのクラスとそのメソッドを実装しています。
次に、「temp2」という別のプロジェクトを作成し、そこで実装したクラスを使用するためにライブラリ「temp」を含めました。
ここで、「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