Menu

# Windows Found My Bug Before I Did. I Just Had to Read the Error Message.
📰

# Windows Found My Bug Before I Did. I Just Had to Read the Error Message.

DEV Community: java·Joseph Boafo Afful·11 days ago
#lOT6x6s1
#devtojava#devto#dev#programming#debugging
Reading 0:00
15s threshold

Sometimes, the hardest part of debugging isn't finding the bug. It's actually paying attention to what the error message is telling you.

Today, I was working on a simple Java task: splitting a string like name=Kwame into a key and a value.

The idea was straightforward:

Find the position of = .

Extract everything before it as the key.

Extract everything after it as the value.

Here's the code:

String text = "name=Kwame" ;

int index = text . indexOf ( '=' );

String key = text . substring ( 0 , index ); String value = text . substring ( index + 1 );

System . out . println ( key ); System . out . println ( value );

Enter fullscreen mode

Exit fullscreen mode

Expected output:

name Kwame

Enter fullscreen mode

Exit fullscreen mode

Simple enough, right?

Where I went wrong

My first implementation looked like this:

String value = text .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.