android program hangs before onCreate is called (beginner)

时光总嘲笑我的痴心妄想 提交于 2020-01-06 05:39:07

问题


I needed some sample code to test out the AudioRecord class and I came across this website
LINK TO THE SOURCE CODE
However the program doesn't run, and hangs after a while. When the program starts it gives blank screen and does not do anything, and after a while a message box pops up saying the program is not responding and whether I want to close it.
So I added Toast.makeText(getApplicationContext(), "HERE", Toast.LENGTH_SHORT).show(); as the first line of onCreate() in MainActivity, but even this toast does not show up on the screen. Where are possible locations where a program may hang, before even calling onCreate()? How can I locate that line of code? I tested it on the emulator.


回答1:


Don't know if its the exact cause but in the XML layout file it makes references to @+id/textView1 but there is no TextView defined in the XML file. This may refer to the TextView that the SDK creates by default to show the "Hello World" label but has been removed from the example given.
In fact looking at the code in the layout more, the line android:layout_alignLeft="@+id/textView1" is wrong because it has @+id/ which means it is trying to assign a new id/ to android:layout_alignLeft instead of making it match the value "@id/textView1".



来源:https://stackoverflow.com/questions/18183978/android-program-hangs-before-oncreate-is-called-beginner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!