Hey,
I'm trying to write some code so i can get a listview witch checkboxes. I wrote my own Adapter for that, but it gives me a NullPointerException when i open the activity the second time.
This is the errormessage:
The line it says the NPE is is this one:
Although, I can't find out what the problem is. I've been googling for a day now.
Anybody got a idea?
I'm trying to write some code so i can get a listview witch checkboxes. I wrote my own Adapter for that, but it gives me a NullPointerException when i open the activity the second time.
Code:
@Override
public View getView(int position, View view, ViewGroup parent) {
view = inflator.inflate(R.layout.activity_pregame_list_item, parent, false);
view.findViewById(R.id.pregameListItemCBReady).setOnClickListener(this);
PreGamePlayerInfo data = (PreGamePlayerInfo) getItem(position);
TextView tv = (TextView) view.findViewById(R.id.pregameListItemTVName);
tv.setText(data.getName());
CheckBox cb = (CheckBox) view.findViewById(R.id.pregameListItemCBReady);
if (data.getName().equals(prefs.getString(context.getResources().getString(R.string.prefKeyUsername), ""))) {
cb.setEnabled(true);
} else {
cb.setEnabled(false);
}
cb.setChecked(data.isReady());
cb.setTag(data);
return view;
}
This is the errormessage:
Code:
03-23 22:10:37.132: E/AndroidRuntime(14090): java.lang.NullPointerException
03-23 22:10:37.132: E/AndroidRuntime(14090): at hoskens.rens.internship.arc_defense.adapters.PreGamePlayerInfoAdapter.getView(PreGamePlayerInfoAdapter.java:65)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.ListView.onMeasure(ListView.java:1175)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.View.measure(View.java:16497)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.View.measure(View.java:16497)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.View.measure(View.java:16497)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
03-23 22:10:37.132: E/AndroidRuntime(14090): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.View.measure(View.java:16497)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-23 22:10:37.132: E/AndroidRuntime(14090): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.View.measure(View.java:16497)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.Choreographer.doFrame(Choreographer.java:544)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.os.Handler.handleCallback(Handler.java:733)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.os.Handler.dispatchMessage(Handler.java:95)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.os.Looper.loop(Looper.java:136)
03-23 22:10:37.132: E/AndroidRuntime(14090): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-23 22:10:37.132: E/AndroidRuntime(14090): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 22:10:37.132: E/AndroidRuntime(14090): at java.lang.reflect.Method.invoke(Method.java:515)
03-23 22:10:37.132: E/AndroidRuntime(14090): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-23 22:10:37.132: E/AndroidRuntime(14090): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-23 22:10:37.132: E/AndroidRuntime(14090): at dalvik.system.NativeStart.main(Native Method)
The line it says the NPE is is this one:
Code:
if (data.getName().equals(prefs.getString(context.getResources().getString(R.string.prefKeyUsername), ""))) {
Although, I can't find out what the problem is. I've been googling for a day now.
Anybody got a idea?