Hello Android: Adam Porter Derek Juba
Hello Android: Adam Porter Derek Juba
Hello Android
See
http://developer.android.com/resources/tutorials/hell o-world.html
Hello Android
Project name: HelloAndroid Application name: Hello, Android Package name: edu.umd.cs.cmsc436 Create activity: HelloAndroid Min SDK: 13
Hello Android
package edu.umd.cs.cmsc436; 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); } }
Hello Android
Running in Eclipse starts Android emulator Note that the emulator can take several minutes to start Once the emulator is loaded, you can leave it running while you test different versions of your code You may need to unlock the emulator
Debugging
package edu.umd.cs.cmsc436; 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"); Object o = null; o.toString(); setContentView(tv); } }
Debugging
Try running the modified application You should get an error message with a Force Close button
Debugging
Now add a breakpoint in the code Run the application in the debugger- when it stops, you can step through the code in Eclipse as normal
Debugging
To find out where an exception occurred in your code, you can look at the LogCat window in the Debug perspective After the application closes, scroll down to find the exception message
Debugging