• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Android Debugging

 
Emillio Carlos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A long time ago I used to be a programmer. Then I realized I hated it and tried something else. Now realize I don't have a job. Point is I used to know Java so I'm not trying to learn that at the same time as the android SDK, just remember it.

Specifically in this example I am getting NullPointerException, and later something says "Source Not Found" in a window labeled ActivtyThread that contains a button that says Edit Source Lookup Path. I would amuse it didn't know where the source was except that I ran the hello world apk just fine using the android SDK and there is nothing I am using that is outside the SDK at this point. But I want to get advice on debugging more than the specific issue. I am trying to get back intro programming and delve into the android sdk. I set up eclipse and the sdk and the emulator etc etc. Been going through tutorials but I got stuck fast on buttons.

Long story short I don't think I'm using the debugging tool correctly or I made some kind of error setting up the environment. Here is my code, excluding imports and the method calculate() in the last line. I hope you survive my naming conventions.

...
public class AndroidSDKLabActivity extends Activity {

private Button button_1;
private TextView defaultTextView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


button_1 = (Button)findViewById(R.id.widget33);
defaultTextView = (TextView)findViewById(R.string.TextView_hello);
button_1.setOnClickListener(new Button.OnClickListener() {public void onClick(View v){ calculate();}});
}

...

I set up breakpoints in my code, and I when I run debug mode I select Run>DebugHIstory>MyAndroidProgram and the app loads on the emulator. But rather than stopping on my breakpoints when in debug mode the app loads and then force quits, then eclipse goes through my break points, but based on commenting out code it the last line that is causing the force quit.

I'm not clear on the concurrency of what I see in eclipse and what is on the emulator. Is debug mode in eclipse just running the code off the JRE in my path, or is it interfacing the emulator. Basically where is my breakpoint stopping the execution? Is it on the emulator? If it is on the emulator then why is the application force quitting on the line that is causing the problem before that part of the code is being executed?

when stepping through the code I am also seeing the variables button_1 and defaultTextVIew as null after they should be instantiated.

I guess basically the issue here is how am I supposed to debug the code and just what exactly is it I am looking at in the eclipse debug mode with respect to what is being run on the AVD. When I see that the variable is null stepping through an app that has already been force quit on the emulator can I assume that it would be null on the emulator?
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Above line has error.

You are trying to find the view using R.string. It should be R.id.<something>

 
Emillio Carlos
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats not the (only) problem. Even when I try to run the sample code from the API:

http://developer.android.com/reference/android/widget/Button.html

I get a message that application has stopped unexpectedly with the only option being to force close. I get a button to draw but when I add the code from the API, copy and paste and change my button id in main.xml to be the same as in the code, I get the error. And more importantly to me I am getting the force close on the emulator BEFORE eclipse hits my breakpoint in debug mode, even though they are on every line in the code.

So to further clarify what I'm asking. If eclipse debug mode isn't showing me the code executing on the emulator, than what is it showing me? and how reliable is whatever eclipse is showing me with respect to emulator?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic