2

I am facing problem while debugging my Java source code using jdb(Java Debugger). when i try to set value in instance variable using scanner class object it will display following output

Jdb Displaying following output

I cant understand why i am getting this message "unrecognized command". My java Source code is as follows

import java.util.Scanner;
class StringPlay{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
    int t;
    // System.out.println("t");
    t=sc.nextInt();
    for(int l=0;l<t;l++){
            String s="",a="";
        int k=0,player=0;
        // System.out.println("s");
        s=sc.next();
        for(int i=0;i<s.length();i++){
            for(int j=i+1;j<s.length();j++){
                if((int)s.charAt(j)!=(int)s.charAt(i)){
                    // strcat(a,s[j]);
                    a+=s.charAt(j);
                    // k++;
                }
                if(j==s.length()-1){
                    s=a;
                    a="";
                    // string::replace(a,0,"");

                    player++;
                }
            }
        }
        if(player%2==0)System.out.println("player1");
        else System.out.println("player2");
    }

    }
}

Well I am using jdb version 1.8 (Java SE version 1.8.0_151). and java version "9.0.1" Java(TM) SE Runtime Environment (build 9.0.1+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

and I am Working on Java in Ubuntu 16.04LTS.

Thanks in advance for helping me.

2
  • I appreciate you attempt to do it the men’s way, however, did you ever consider using an IDE like Eclipse, Netbeans, or IntelliJ instead of command line jdb? The win in productivity, especially when debugging is huge… Commented Feb 5, 2018 at 11:48
  • Hey thanks @Holger Well I don't try on eclipse or on other IDE Commented Feb 5, 2018 at 13:01

2 Answers 2

1

Try feeding the Scanner an input string for debugging with jdb. Because your console input is being read by the jdb and not by the Scanner class.

You can try:

String myInput = "This is my input, that I want in my sc.";
Scanner sc = new Scanner(myInput);

Or you can feed it directly:

Scanner sc = new Scanner("This is my input, that I want in my sc.");
Sign up to request clarification or add additional context in comments.

4 Comments

ohh..I want input form user not from system.
Yes, like I said, for debugging with jdb you should use that, and for running a program without jdb use System.in.
OK, but Is we cant take input while debugging the program??
Well,dude it still dose not work. now it will display "Nothing Suspended" error.
0

Got this info from this post:

You're going to need to split up the running of your app, and the debugging in two different terminals.

The first terminal needs to just run the app, but to run it in a way that jdb can connect to it later. You can do this with this command: java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n MyClass

In your second debug window, you need to connect to your Java app by running: jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8000

Now, in order to put in values so your Scanner can read it, go back to the first terminal (the one running the app) and enter the arguments as normal.

Any breakpoints you set up will hit in your second debugging window.

Hopefully that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.