当我尝试运行我的脚本时,在logcat中出现这样的错误。我比较它,它是onClickListener。任何建议来解决这个问题?仍然是初学者。Logcat错误onclicklistener android
0
A
回答
2
问题存在的位置:
View splashscreen = (View) findViewById(R.layout.splash);
splashscreen.setOnClickListener(this);
你得到一个例外,因为splashscreen
为空,并在一个空指针调用setOnClickListener()
是不允许的。指针为null的原因是因为您需要使用正确的ID从XML获取对视图的引用。您的splash.xml
位于res/layout中的文件正在作为活动的内容视图加载,但您应具有与该特定视图关联的适当的R.id
值。
在splash.xml
中,为此目的声明的视图在其XML声明(我挑选了“某物”空气中,该标识符可以是任何你想要的)时应该具有android:id="@+id/something"
属性。然后,您可以拨打:
//Hint: You don't have to cast the result if the pointer is a plain vanilla View
View splashscreen = findViewById(R.id.something);
splashscreen.setOnClickListener(this);
然后你会得到的观点和你的一套方法不会失败的有效参考。
HTH
0
正如Devunwired说,我想也许你错布局和ID。
见http://developer.android.com/reference/android/view/View.html
0
是,Devunwired是正确的。您必须将资源ID赋予特定视图。而不是你要给布局文件名称的引用作为“splash.xml”。
也尝试使Id名称与布局文件名称不同。它不是和错误,但有时发生,使得可能引发问题理解并给予资源id不同的参考。
谢谢。
0
而不是使用Thread
的,你可以尝试Handler
:
Handler handler = new Handler();
handler.post(new Runnable(){
public void run(){
//TODO
}
});
顺便说一句,张贴多个异常堆栈跟踪会更有帮助。
相关问题
- 1. Android Logcat错误
- 2. 错误的logcat的Android
- 3. LogCat中的Android SensorManager错误
- 4. Android datarouter logcat错误信息
- 5. Android Logcat错误消息。
- 6. Android上的logcat错误EditText
- 7. Android logcat错误TundConnector和NetlinkEvent
- 8. OnClickListener错误
- 9. 错误的logcat
- 10. Logcat java.lang.ExceptionInInitializerError错误?
- 11. OnClickListener NullPoinerException错误?
- 12. SWT/LogCat中的错误?或Android 2.2 AVD
- 13. Android的原因不明的logcat错误
- 14. 如何解决Android中的Logcat错误
- 15. Android Studio Logcat不显示错误
- 16. Android上使用httpclient获取logcat错误
- 17. “错误报告WTF”在logcat的错误
- 18. logcat指示错误?
- 19. OnClickListener和CheckBox错误
- 20. Logcat错误 - qtaguid - 失败write_ctrl
- 21. Android的Eclipse的错误:logcat的连续接收“MPL-FIFO错误”
- 22. Logcat限制或错误
- 23. LogCat。如何追踪错误?
- 24. 如何解决logcat错误?
- 25. 通过SharedPreferences/logcat的错误
- 26. 奇怪的LogCat错误
- 27. 安卓LogCat共享库找不到错误LogCat
- 28. Android - LogCat
- 29. onclickListener android
- 30. Android的新的Android应用程序项目的logcat错误