在Netbeans中调试Java [英] Debugging Java in Netbeans

查看:62
本文介绍了在Netbeans中调试Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的初学者.我正在尝试调试一个简单的程序,该程序返回输入数字的位数.插入断点并开始调试后,它会显示没有变量,因为没有当前线程,因此无法显示"

I'm a beginner in java. I'm trying to debug a simple program that returns the number of digits of an entered number. After inserting the breakpoint and starting debugging it says "No variable to display because there is no current thread"

package learning1;

import java.util.Scanner;
import java.lang.Math;
public class Learning1 {

 public static void main(String[] args) { 
     int a;
     Scanner scan = new Scanner (System.in);
     System.out.print("Enter number");
     a = scan.nextInt();
     int i=a;
     int count=0;
     while(i>1){
         i = a%10;
         count = count + 1;
     }
     System.out.print("Number of digits is " + count );
   }

}

推荐答案

好吧,这取决于放置断点的位置.用鼠标指针单击编辑器行号,其中该行:

Well, it depends where you place your breakpoint. Take your mouse pointer and click on the editor line number where the line:

public static void main(String[] args) { 

位于.行号上方应出现一个浅红色三角形:

is located. A light red triangle should appear over the line number:

,或者您可以在 main()方法中的一行上设置断点.例如,如果单击编辑器行号12,您将看到一个淡红色的正方形,并且整个代码行本身都以相同的颜色突出显示:

or you can set a break-point on a line within the main() method. For example, if you click on the editor line number 12 you will see a light red square and the entire code line itself is highlighted with the same color:

现在您所需要做的就是选择 Debug Project 工具栏按钮或从 Debug 菜单栏中选择 Debug Project 来运行您的应用程序在调试模式下:

Now all you need to do is select the Debug Project toolbar button or select Debug Project from the Debug menu bar to run your application in Debug mode:

当代码运行并到达断点时,红色突出显示的行将变为绿色,您可以查看变量,然后在编辑器下方窗格的 Variables 标签中对变量进行声明和初始化:

When your code runs and it reaches the break point the red highlighted line will turn green and you can view your variables as then become declared and initialized within the Variables tab of the pane below the editor:

只需一次按一下键盘上的 F8 键,即可一次浏览一行代码.

To step through your code one line at a time just hit the F8 key on your keyboard.

这篇关于在Netbeans中调试Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆