问题
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