0% found this document useful (0 votes)
81 views

Hello Android: Adam Porter Derek Juba

The document discusses creating an Android "Hello World" application. It describes how to create an Android Virtual Device (AVD) to emulate an Android device, create a new Android project called "HelloAndroid" with an activity, write the code for the activity that displays "Hello, Android", run and debug the application using Eclipse, and view error messages in the LogCat window.

Uploaded by

Vũ Huy Lâm
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Hello Android: Adam Porter Derek Juba

The document discusses creating an Android "Hello World" application. It describes how to create an Android Virtual Device (AVD) to emulate an Android device, create a new Android project called "HelloAndroid" with an activity, write the code for the activity that displays "Hello, Android", run and debug the application using Eclipse, and view error messages in the LogCat window.

Uploaded by

Vũ Huy Lâm
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Hello Android

Adam Porter Derek Juba

Hello Android

See

http://developer.android.com/resources/tutorials/hell o-world.html

Create an Android Virtual Device


AVD is a configuration of emulator options Each AVD includes


Hardware Platform Other options

e.g., Skin, Screen dimensions, SD card size

Storage area Can be created in Android SDK and AVD manager

Hello Android

Create a new Android project


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

Now insert a bug in the code

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

You might also like