Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse Java Debugging(How to debug an Eclipse Java program)
Eclipse Java Debugging [message #1843402] Tue, 27 July 2021 21:27 Go to next message
Mark Hollinger is currently offline Mark HollingerFriend
Messages: 2
Registered: July 2021
Junior Member
import java.util.*;

public class dd_to_dms {

	public static void main(String[] args) {
		int decdeg_position = 0, m_position = 0, s_position = 0;
        double minutes = 0, seconds = 0;
        String decdeg = null, degrees = null, fracpart = null;
        String min = null, m = null, sec = null, s = null;
        
        Scanner in = new Scanner(System.in);
        
        System.out.println("Enter dd: ");
        decdeg = in.nextLine();
        in.close();
        
        decdeg_position = decdeg.indexOf('.');
        
        switch (decdeg_position) {
            case 1: degrees = decdeg.substring(0, 1);
                fracpart = decdeg.substring(1, 6);
                minutes = Double.parseDouble(fracpart) * 60;
                min = Double.toString(minutes);
                m = min.substring(0, 2);
                m_position = m.indexOf('.');
                
                if (m_position == 1) {
                    m = min.substring(0, 1);
                    m = "0" + m;
                }
                        
                sec = min.substring(2, 4);
                seconds = Double.parseDouble(sec) * 60;
                s = Double.toString(seconds);
                s = s.substring(0, 2);
                s_position = s.indexOf('.');
                
                if (s_position == 1) {
                    s = s.substring(0, 1);
                    s = "0" + s;
                }
                break;
            case 2: degrees = decdeg.substring(0, 2);
                fracpart = decdeg.substring(2, 7);
                minutes = Double.parseDouble(fracpart) * 60;
                min = Double.toString(minutes);
                m = min.substring(0, 2);
                m_position = m.indexOf('.');
                
                if (m_position == 1) {
                    m = min.substring(0, 1);
                    m = "0" + m;
                }
                        
                sec = min.substring(2, 4);
                seconds = Double.parseDouble(sec) * 60;
                s = Double.toString(seconds);
                s = s.substring(0, 2);
                s_position = s.indexOf('.');
                
                if (s_position == 1) {
                    s = s.substring(0, 1);
                    s = "0" + s;
                }
                    break;
            case 3: degrees = decdeg.substring(0, 3);
                fracpart = decdeg.substring(3, 8);
                minutes = Double.parseDouble(fracpart) * 60;
                min = Double.toString(minutes);
                m = min.substring(0, 2);
                    m_position = m.indexOf('.');
                
                if (m_position == 1) {
                    m = min.substring(0, 1);
                    m = "0" + m;
                }
                        
                   sec = min.substring(2, 4);
                   seconds = Double.parseDouble(sec) * 60;
                   s = Double.toString(seconds);
                   s = s.substring(0, 2);
                   s_position = s.indexOf('.');
                
                if (s_position == 1) {
                    s = s.substring(0, 1);
                    s = "0" + s;
                }
                break;
            }
        
        System.out.println(degrees + "°" + m + "'" + s + "\"");
        
/*
 * In the console after running the program I get
 * 
 *  Enter dd: 
 *  46.0000
 *  Exception in thread "main" 
 *   java.lang.StringIndexOutOfBoundsException: begin 2, end 4, length 3
 *  at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
 *  at java.base/java.lang.String.substring(String.java:1874)
 *  at dd_to_dms.main(dd_to_dms.java:55)
 */

	}
}



Looking at the IDE-generated data, I assume the error begins at line 55. I set a breakpoint (right-click, then a dot appeared) at line 55, and a rectangle appeared at line 65. How do I step through the program so I can see what's going on? The program converts a double from decimal degrees to degrees-minutes-seconds format.
Re: Eclipse Java Debugging [message #1843406 is a reply to message #1843402] Wed, 28 July 2021 01:37 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4169
Registered: July 2009
Senior Member

It's not that different from launching it in Run mode.

https://help.eclipse.org/2021-06/topic/org.eclipse.jdt.doc.user/tasks/tasks-debug-launch.htm?cp=1_3_6_1_1


Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Eclipse Java Debugging [message #1843444 is a reply to message #1843406] Thu, 29 July 2021 23:21 Go to previous message
Mark Hollinger is currently offline Mark HollingerFriend
Messages: 2
Registered: July 2021
Junior Member
Thank you for replying!
Previous Topic:Eclipse 2021-06 - adoptJDK
Next Topic:SAP UI5 Wizard missing in 2020-06
Goto Forum:
  


Current Time: Fri Jan 28 21:37:40 GMT 2022

Powered by FUDForum. Page generated in 0.03128 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top