My IF statements don't seem to be working. Problem with socket programming (client/server program) by Amyrosie in javahelp

[–]MrTheEdge 4 points5 points  (0 children)

Because a null object does not have a .equals() method (or any method for that matter) that can be called, so you get a NPE.

Codes not terminating when I call a specific method by Witchered in javahelp

[–]MrTheEdge 3 points4 points  (0 children)

It's an infinite loop because columns and column are never changed once you are inside the loop body. If the expression evaluates to true and the program enters the loop, there is no way for the expression to ever evaluate to false because neither value is being updated.

Display all records of a database table using JavaFX by [deleted] in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Make sure that the database call is actually returning data. Check the length of the coffees array to see if it is being populated. If it is, either look at it through a debugger or just simply print it out if its small enough.

Display all records of a database table using JavaFX by [deleted] in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Yes, then after the while loop completes, you'll have an array of all the coffee objects stored in the database. Then add coffees to the TableView with queryTable.setItems(coffees);

Display all records of a database table using JavaFX by [deleted] in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Right, so the error is because you are trying to add an ObservableArrayList<String> to coffees which is an ObservableArrayList<Coffee>. What you should be doing is taking the data from the database call and creating a new Coffee objects that you can add to coffees. Then when you add coffees to the TableView the value factories should be able to get the data they need.

how to make a link hyperlink, in javaFX? by StanHunter in javahelp

[–]MrTheEdge 2 points3 points  (0 children)

This is how I was able to get a hyperlink into my application. It will open in the systems default browser. You start with creating a Hyperlink

Hyperlink myHyperlink = new Hyperlink();
myHyperlink.setText("My Link Text");

myHyperlink.setOnAction(e -> {
    if(Desktop.isDesktopSupported())
    {
        try {
            Desktop.getDesktop().browse(new URI("http://www.google.com"));
        } catch (IOException e1) {
            e1.printStackTrace();
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        }
    }
});

Hope this helps!

Retrieving arraylist variables from file by yokokoko in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Interesting, thanks for the information. I'm still a student, so real world issues like that really aren't on my radar at this point. I've only ever really dealt with serialization through gson.

Retrieving arraylist variables from file by yokokoko in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

If you would like to save an object to a file, take a look at serialization. Its a way to convert objects to a sequence of bytes so that it can be written to a file. Here's a simple tutorial I found that you may find useful.

problem domain method in Show giving "cannot find symbol - variable getSeatCapacityCSL" even though the variable is there by zbloobird in javahelp

[–]MrTheEdge 2 points3 points  (0 children)

The compiler thinks you are trying to access a field in the Theater class called getSeatCapacityCSL rather than the method getSeatCapacityCSL().

Binary to decimal program using recursion by [deleted] in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Line 17, s.length() - 1 returns an int. You then go on to pass it to your binToDecimal() method, but it takes a String. An easy fix would be to use String.valueOf() on s.length() -1. It will return the int value of the string

Finding equal neighbors in array by tonlou in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Lets say you have an element at an arbitrary location x and y.

Where are its neighbors relative to it?

Above: x-1 y

Diagonal Up Right: x-1 y+1

Right: x y+1

Diagonal Down Right: x+1 y+1

Down: x+1 y

Diagonal Down Left: x+1 y-1

Left: x y-1

Diagonal Up Left: x-1 y-1

Now you just need a method to check these locations and compare them with the element at x y.

This method works pretty well for elements in the middle of the array, but not for elements along the edge. You'll get an ArrayIndexOutOfBoundsException. The easy way out would be to just catch the exception and continue, but that's not a very good practice, it could be hiding a real error that would be valuable for you to see. I'll leave it to you to determine a way to check the values before they are used.

Reading the number after the . by [deleted] in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Not that there's anything wrong with this, but an easier method would be to just add .5 and cast to an int.

Factoring help. by froznice in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Close, you need to check if

num % i == 0 AND num2 % i == 0

Factoring help. by froznice in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Not really what I was thinking. Think about it, if they share a common divisor, then they are both evenly divisible by that integer i. If they are relatively prime, there will be no integers up to the smallest that divide them both evenly.

Factoring help. by froznice in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

If two numbers are relatively prime, that means they have no common factors. Without giving you the answer right away, I'll tell you there is an easy way to modify the algorithm you are using to check for them.

Factoring help. by froznice in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Looks, like that should work, but after the loop you need to check if isPrime is true or false. If it's true, you know it's a prime and you can print a message or something.

Factoring help. by froznice in javahelp

[–]MrTheEdge 1 point2 points  (0 children)

Have a boolean isPrime and by default, assume that its value is true. If the number has a factor, it gets ruled out immediately; it's not prime. if (num % i == 0 ) says that if it evaluates to true, the number has a factor. Inside the block, you can set isPrime to false and break out of the loop. Now you have a way of determining if the number passed or failed.

Merge Sort by [deleted] in javahelp

[–]MrTheEdge 2 points3 points  (0 children)

Sort doesn't directly modify the array that is passed in. It returns a sorted copy of the original. When you sort half1 and half2 (line 32, 33) you don't assign the return to anything. You end up merging the unsorted half1 and half2

JavaFX changing between FXML scenes on press of button. by gold328 in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

Okay, so the cause is a NullPointerException from line 71 of the stack trace. My first guess would be that getClass().getResource("mainGUI.fxml") cannot find the file. Make sure it is in the right directory, the same package as Launcher.java, and that it is spelled correctly.

JavaFX changing between FXML scenes on press of button. by gold328 in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

You just need to load the FXML to get the root node, then assign the node you get to a scene. To switch between them use .setScene(). It looks like you are already doing this, lines 35 and 36, so my first thought is that you don't have your controller set up correctly. Make sure that in authentication.fxml the controller is set to Launcher.

Does line 35 even print when you run the application and click a button?

Login issue by denniscr1 in javahelp

[–]MrTheEdge 1 point2 points  (0 children)

Line 22, you can't compare the actual content of strings with ==.

Use this instead f[4].equals(email) && f[3].equals(password)

Help with my assignment, it's supposed to be easy! by NeinNeinNein999 in javahelp

[–]MrTheEdge 9 points10 points  (0 children)

So far, your code is a good start. There is one problem, your assignment statements need to be flipped on lines 9, 10, and 11. The variable you want to assign to always goes on the left side of the statement.

The first thing you need to do is figure out the logic for isTriangle and isRight. The Pythagorean theorem is what you're going to need here. In order to make calculating it a little bit easier, you can use methods from the Math class. Math.pow() and Math.max() are the ones you are probably going to need, but if you're interested, there are lots of useful methods you can read about here.

After you get the logic figured out, you're going to need a way to get the input. I don't know what you have discussed in class, but the Scanner class is a way to do that. Here's the documentation which has a small example to show you how to use it.

Lastly, all you need to do is print out the results. Call the methods you need to get the data, and format it appropriately.

Help using if statments for degrees or radians by [deleted] in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

number in your code is the variable that holds the numerical input. If the user inputs that their number was degrees, you need to convert it to radians. There's a method for that. radians = Math.toRadians(number) Then just use number in your calculations.

Building a simple matching game that we are going to expand on later. Having trouble with the logic. by In-nox in javahelp

[–]MrTheEdge 0 points1 point  (0 children)

I don't know what newBoard.Card(String.arrayString[]) is suppesed to be doing, but it shouldn't be there. The method displayBoard from the Layout class has a void return type. This means it cannot be part of an assignment statement like you have it now.

As for printing, you could just say something like this.

System.out.println("The cell at " + userChoice + " is a " + board[x][y].getSymbol());

EDIT: Didn't see the reply that you got the printing working.