开发者

How to use Android Eclipse Debugging? And unknown error on a simple code

I have two questions, I took the below code from a tutorial website in the process of trying to learn and find out how to set a countdown timer. But when I started the up in the emulator it crashed before starting and android force closed it. So here are my two questions:

1-What, or where is the line that caused the error? 2-I put break point on the onCreate method, and switched to the debugger view, and here I couldn’t know how to use the debugger view in Eclipse. Where to look for the faulty error, and why the Eclipse debugger doesn’t highlight the line it is stopping on?

I would love to get answer for the 2nd question more than the first. Obviously :)

Thanks to anyone for helping, or trying to help.

public class MytestActivity extends Activity {
       /** Called when the activity is first created. */
         TextView tv; //textview to display the countdown
         //final TextView tv = (TextView) findViewById(R.id.editText1);

         @Override
         public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                //final TextView tv = (TextView) findViewById(R.id.editText1);

                tv = new TextView(this);
                this.setContentView(tv);

                //5000 is the starting number (in milliseconds)
                //1000 is the number to count down each time (in milliseconds)
                MyCount counter = new MyCount(5000,1000);
                        counter.start();
         }; //end of onCreate class

         //countdowntimer is an abstract class, so extend it and fill in methods
         public class MyCount extends CountDownTimer{

                public MyCount(long millisInFuture, 开发者_StackOverflow社区long countDownInterval) {
                       super(millisInFuture, countDownInterval);
                }

                @Override
                public void onFinish() {
                       tv.setText("done!");
                }

                @Override
                public void onTick(long millisUntilFinished) {
                       tv.setText("Left: " + millisUntilFinished/1000);

                }

         } //end of MyCount class

} //End of activity class


take a look at this picture I've embedded. It shows how to debug and step through code.

How to use Android Eclipse Debugging? And unknown error on a simple code

After hitting a debug point, it should look like that.

See 9 for the stack trace.


Log Cat is a much better solution for debugging then the standard debugging techniques. Learning to use it correctly is a big step for a fledgling Android programmer. Here is a handy video that will hopefully get you started: http://www.youtube.com/watch?v=wPaUxCrp6qI


First, set android:debuggable="true" in manifest file and try again. This is explained in detail at http://developer.android.com/guide/topics/manifest/application-element.html. Then you can walk through the code. Also, look in the stack trace, at force close, it will usually hint at the cause.


Well I haven't used the debbuger but in the eclipse for android programming there is an useful tool that is called the LogCat. you can access it from window>> show view and if it doesn´t appear there you can find it in other. You have to connect your phone (also the computer have to get installed already the drivers for the phone) and you can put some Log instructions in your code so you can see them in the Logcat and see where the programm is not reaching and with this where the programm is crashing. An example of this code is the line: Log.d("TAG","you reached here!!!!!!"); The d is the kind of Log is going to appear (there are several ones; see more info here: Android Log description). You can also get in the logcat the values of the variables that you are using; an example of this will be: Log.d("TAG","The value of X is: " + X); Where X is the name of a variable. Hope this will help you =)

Another thing: you have to set your phone debbugable true and same at the android manifest

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜