我有一个PreferenceScreen,然后动态创建一个PreferenceCategory,在这个类别中我设置了布局newCategory.setLayoutResource(<PackageName>.R.Layout.myLayout); 。 布局是几个TextView和一个按钮。 当我尝试更改这些TextViews TextView tvTextView = (TextView) findViewById(<PackageName>.R.id.tvTextView);的文本时, TextView tvTextView = (TextView) findViewById(<PackageName>.R.id.tvTextView); tvTextView.setText("Test"); 我得到java.lang.NullPointerException 。 我不知道到底发生了什么,我正在把头发拉出来,这一定是非常简单的我不会得到的。
Log Cat:希望这是我想复制的正确的东西= 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)第190行有tvTextView.setText("Test"); ,这就是错误发生的地方。
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.
最满意答案
谢谢大家帮忙快速回复,但我想出了一个不同的方法。 谢谢你的时间。
Thanks guys for helping out with speedy replies, but I figured out a different approach. Thanks for your time.
更多推荐
java,AndroidRuntime,电脑培训,计算机培训,IT培训"/> <meta name="descripti
发布评论