![]() 05/28/2020 at 11:47 • Filed to: None | ![]() | ![]() |
!!!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”);}
}
}
![]() 05/28/2020 at 12:31 |
|
I thought this thread was going to be about something else entirely. You can guess how I was going to answer.
But no, sorry.
![]() 05/28/2020 at 12:32 |
|
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.
![]() 05/28/2020 at 12:33 |
|
That’ s some good java.
![]() 05/28/2020 at 12:37 |
|
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!
![]() 05/28/2020 at 12:39 |
|
Here’s the method I’m talking about https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.String-
![]() 05/28/2020 at 12:40 |
|
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);}
![]() 05/28/2020 at 12:45 |
|
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.
![]() 05/28/2020 at 12:46 |
|
Java you say?
![]() 05/28/2020 at 12:50 |
|
I love it!
![]() 05/28/2020 at 12:56 |
|
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.
![]() 05/28/2020 at 12:57 |
|
I was a little disappointed this post was not about coffee as well lol
![]() 05/28/2020 at 13:44 |
|
+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.
![]() 05/28/2020 at 13:56 |
|
I owe you a beer. Much appreciated!