Any Java bros in the house? *Solved*

Kinja'd!!! "nFamousCJ - Keeper of Stringbean, Gengars and a Deezul" (nfamouscj)
05/28/2020 at 11:47 • Filed to: None

Kinja'd!!!0 Kinja'd!!! 13

!!!error: Indecipherable SUB-paragraph formatting!!! got it.

Essentially the window prompt will ask for an input, it checks it against a series of IF statements and when it finds the right one it launches the web browser and goes to a specific URL.

But in my test it’s never satisfying the IF conditions and always triggering ELSE. Field1.getText() is returning the field input. //Including imgur link for easier visual : //pastebin link:

!!! UNKNOWN CONTENT TYPE !!!

!!! UNKNOWN CONTENT TYPE !!!

//Omitting JFtextfield/frame building code.

{

String input = field1.getText();

if(ae.getActionCommand().equals(“Reboot”)) //button is labeled “Reboot”

if (input == “9") { //inputting 9 into field // SHOULD BE if (input.equals(“9")) {

try {

Desktop desktop = java.awt.Desktop.getDesktop();

URI oURL = new URI(“ !!!error: Indecipherable SUB-paragraph formatting!!! ;

desktop.browse(oURL);

} catch (Exception e) {

e.printStackTrace();

}

}

else { System.out.println(“Check camera name”);}

}

}


DISCUSSION (13)


Kinja'd!!! This is what we'll show whenever you publish anything on Kinja: > nFamousCJ - Keeper of Stringbean, Gengars and a Deezul
05/28/2020 at 12:31

Kinja'd!!!3

I thought this thread was going to be about something else entirely. You can guess how I was going to answer.

Kinja'd!!!

Kinja'd!!!

But no, sorry.


Kinja'd!!! TheRealBicycleBuck > nFamousCJ - Keeper of Stringbean, Gengars and a Deezul
05/28/2020 at 12:32

Kinja'd!!!2

I’m not a java bro, but I always find it valuable to print the two variables being compared to make absolutely sure that the value is what I’m expecting.

I run into slash and backslash problems all the time in python and printing the variables usually helps me find my error.


Kinja'd!!! nFamousCJ - Keeper of Stringbean, Gengars and a Deezul > This is what we'll show whenever you publish anything on Kinja:
05/28/2020 at 12:33

Kinja'd!!!2

That’ s some good java.


Kinja'd!!! CompactLuxuryFan > nFamousCJ - Keeper of Stringbean, Gengars and a Deezul
05/28/2020 at 12:37

Kinja'd!!!2

My guess would be you’re comparing references instead of the value. You need to use strings.Equals or something like that. Basically treat the strings as objects (or pointers) instead of primitives. Hope that makes sense!


Kinja'd!!! CompactLuxuryFan > CompactLuxuryFan
05/28/2020 at 12:39

Kinja'd!!!1

Here’s the method I’m talking about  https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.String-


Kinja'd!!! Just Jeepin' > nFamousCJ - Keeper of Stringbean, Gengars and a Deezul
05/28/2020 at 12:40

Kinja'd!!!2

I haven’t written any Java in 25 years, but you should be able to see the unexpected value by replacing your else block with this:

else { System.out.println(input);}


Kinja'd!!! CompactLuxuryFan > CompactLuxuryFan
05/28/2020 at 12:45

Kinja'd!!!1

So in your code instead of input == “9”, you do input.equals(“9”). Sorry if that’s too specific but I wasn’t sure if I was being clear.


Kinja'd!!! ttyymmnn > nFamousCJ - Keeper of Stringbean, Gengars and a Deezul
05/28/2020 at 12:46

Kinja'd!!!1

Java you say?


Kinja'd!!! ClassicDatsunDebate > This is what we'll show whenever you publish anything on Kinja:
05/28/2020 at 12:50

Kinja'd!!!1

I love it!


Kinja'd!!! CalzoneGolem > nFamousCJ - Keeper of Stringbean, Gengars and a Deezul
05/28/2020 at 12:56

Kinja'd!!!2

Fuck Java and Java script. I know many programming languages and have forgotten many more. Anything with the word Java in it fries my synapses immediately .

My senior project was entirely in Java. My poor partner did all the coding while I did the rest. He felt like he got the better part of that deal but he was wrong. So so wrong.


Kinja'd!!! MasterMario - Keeper of the V8s > This is what we'll show whenever you publish anything on Kinja:
05/28/2020 at 12:57

Kinja'd!!!1

I was a little disappointed this post was not about coffee as well lol


Kinja'd!!! t0ast > CompactLuxuryFan
05/28/2020 at 13:44

Kinja'd!!!1

+1 from someone who has to deal with this on a semi-regular basis. String.equals() will compare the contents of String , == will compare the String objects themselves. “9" used inline in that if statement can be thought of as its own object and therefore != input.


Kinja'd!!! nFamousCJ - Keeper of Stringbean, Gengars and a Deezul > CompactLuxuryFan
05/28/2020 at 13:56

Kinja'd!!!0

I owe you a beer. Much appreciated!