I am trying to run a simple program hello world
in my android mobile.
but the application stops unexpectedly.
the apk
file is installing easily but it is not running.
I do not understand why this happens
helloWorld.java
package com.hellos;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
Follow the Hello World Tutorial
If you already are and have followed it correctly (emulator installed etc) then everything should be working.
I know this may sound odd, but if you are sure all was done right try copy and pasting your code into a new project and try launching it again. (Others have done this here on SO and it has worked.)
I have had errors like this in other things, and its usually something that the phone/emulator does not like for some reason (when I think everything should work). Try to dumb down (This will behard since its hello world) your xml etc, and see if you can get it to run.
Your code should look as follows
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv); }
}
精彩评论