I have a PreferenceScreen and then dynamically create a PreferenceCategory, and on this category I set the layout newCategory.setLayoutResource(<PackageName>.R.Layout.myLayout);
. The layout is a couple of TextView's and a button. When I try to change the text of these TextViews TextView tvTextView = (TextView) findViewById(<PackageName>.R.id.tvTextView);
tvTextView.setText("Test");
I get java.lang.NullPointerException
. I have no idea what the hell is going on, and I am pulling my hair out, it must be something very simple I am not getting.
Log Cat: Hope this is the right stuff I am meant to copy =S
12-16 23:25:23.450: E/AndroidRuntime(5412): FATAL EXCEPTION: main
12-16 23:25:23.450: E/AndroidRuntime(5412): java.lang.NullPointerException
12-16 23:25:23.450: E/AndroidRuntime(5412): at <PackageName>.GpsLocation$2.onClick(GpsLocation.java:190)
12-16 23:25:23.450: E/AndroidRuntime(5412): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
12-16 23:25:23.450: E/AndroidRuntime(5412): at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 23:25:23.450: E/AndroidRuntime(5412): at android.os.Looper.loop(Looper.java:144)
12-16 23:25:23.450: E/AndroidRuntime(5412): at android.app.ActivityThread.main(ActivityThread.java:4937)
12-16 23:25:23.450: E/AndroidRuntime(5412): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 23:25:23.450: E/AndroidRuntime(5412): at java.lang.reflect.Method.invoke(Method.java:521)
12-16 23:25:23.450: E/AndroidRuntime(5412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-16 23:25:23.450: E/AndroidRuntime(5412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-16 23:25:23.450: E/AndroidRuntime(5412): at dalvik.system.NativeStart.main(Native Method)
The line 190 has tvTextView.setText("Test");
, that's where the error is happening apparently.