私はAndroidコードを持っていますが、これをerror : Nullpointerexception
ロードするときは常に、これは次のメソッドです:listview
adapter
loadlist
fragment
ロードリストは285行目
private void loadList() {
// TODO Auto-generated method stub
resultList = getListData();
final ListView listView = (ListView) rootView.findViewById(R.id.pbb_data_op_list);
listView.setAdapter(new LogListAdapter(rootView.getContext(), createDummyData()));
}
そして、これはリストビューのダミーだけを作成します
public List<ACTIVITY_LOG> createDummyData() {
List<ACTIVITY_LOG> logs = new ArrayList<ACTIVITY_LOG>();
ACTIVITY_LOG log = new ACTIVITY_LOG();
log.setmMenu(MenuString.MENU_PBB);
log.setmSubMenu("Verifying");
log.setmAktifitas("Melakukan Insert Data");
log.setmDate(new Date());
ACTIVITY_LOG log2 = new ACTIVITY_LOG();
log2.setmMenu(MenuString.MENU_X);
log2.setmSubMenu("DATA OP");
log2.setmAktifitas("Melakukan Insert Data sofie");
log2.setmDate(new Date());
logs.add(log);
logs.add(log2);
for (int i = 0; i < 20; i++) {
int counter = 1200;
ACTIVITY_LOG log3 = new ACTIVITY_LOG();
log3.setmMenu(MenuString.MENU_X);
log3.setmSubMenu("DATA OBJEK PAJAK");
log3.setmAktifitas("Melakukan Update Data "
+ (counter + i) + ".0");
log3.setmDate(new Date());
logs.add(log3);
}
return logs;
}
これはログ リスト アクティビティです。
public class LogListAdapter extends BaseAdapter {
private Context thisContext;
private List<ACTIVITY_LOG> thisListData;
private LayoutInflater layoutInflater;
public LogListAdapter(Context context, List listData) {
// TODO Auto-generated constructor stub
thisContext = context;
thisListData = listData;
layoutInflater = LayoutInflater.from(thisContext);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return thisListData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return thisListData.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.log_list_item_layout,
null);
holder = new ViewHolder();
holder.gambarMenuView = (ImageView) convertView
.findViewById(R.id.gambar_menu);
holder.subMenuView = (TextView) convertView
.findViewById(R.id.sub_menu_nama);
holder.aktifitasView = (TextView) convertView
.findViewById(R.id.aktifitas_nama);
holder.tanggalView = (TextView) convertView
.findViewById(R.id.aktifitas_tanggal);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
int menuId = thisListData.get(position).getmMenu();
holder.gambarMenuView.setImageResource(MenuString.getMenuImage(menuId));
holder.subMenuView.setText(thisListData.get(position).getmSubMenu());
holder.aktifitasView
.setText(thisListData.get(position).getmAktifitas());
holder.tanggalView
.setText(thisListData.get(position).getmDate() != null ? thisListData
.get(position).getmDate().toString()
: "");
return convertView;
}
static class ViewHolder {
ImageView gambarMenuView;
TextView subMenuView;
TextView aktifitasView;
TextView tanggalView;
}
}
これはlogcatです:
09-02 16:20:08.646: E/AndroidRuntime(14848): FATAL EXCEPTION: main
09-02 16:20:08.646: E/AndroidRuntime(14848): java.lang.NullPointerException
09-02 16:20:08.646: E/AndroidRuntime(14848): at com.imotax.fragments.pbb.PBBDataOPFormLSPOPFragment.loadList(PBBDataOPFormLSPOPFragment.java:285)
09-02 16:20:08.646: E/AndroidRuntime(14848): at com.imotax.fragments.pbb.PBBDataOPFormLSPOPFragment.access$0(PBBDataOPFormLSPOPFragment.java:278)
09-02 16:20:08.646: E/AndroidRuntime(14848): at com.imotax.fragments.pbb.PBBDataOPFormLSPOPFragment$1.onItemSelected(PBBDataOPFormLSPOPFragment.java:141)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.widget.AdapterView.access$200(AdapterView.java:49)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:860)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.os.Handler.handleCallback(Handler.java:615)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.os.Handler.dispatchMessage(Handler.java:92)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.os.Looper.loop(Looper.java:153)
09-02 16:20:08.646: E/AndroidRuntime(14848): at android.app.ActivityThread.main(ActivityThread.java:4987)
09-02 16:20:08.646: E/AndroidRuntime(14848): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 16:20:08.646: E/AndroidRuntime(14848): at java.lang.reflect.Method.invoke(Method.java:511)
09-02 16:20:08.646: E/AndroidRuntime(14848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
09-02 16:20:08.646: E/AndroidRuntime(14848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
09-02 16:20:08.646: E/AndroidRuntime(14848): at dalvik.system.NativeStart.main(Native Method)
理由はわかりませんが、この問題のように loadlist メソッドではなく他のアクティビティでこれを作成すると、機能します。理由や解決策はありますか?