So I'm coding a Battleship program, and I already am nearly done with my Client and Server. All my other classes are working (methods references in this post and the code I posted below, but they seem to be working just fine, so I think it's the logic), other than my core game logic, it seems. After placing ships, both my client and server decide to shut down. Depending on the run, sometimes it does get to the last method (having the prints occur), startPVP3() (in the code below), however it still causes this error, and still crashes and has weird print messages such as printing "Successful connection to server" late as you can see in the output.
For some reason, these are the outputs I get. I put number tags such as 220 to pinpoint issues, however it does not seem to help much. I also have slightly different systems for placing ships since the same system as the server caused even more issues for the client.
In short, what is the actual problem here? What causes these errors and why do the loops in the startPVP2() methods in the code of the two classes (not the same project) act so strangely? I'm new to networking and I've looked at this for hours and still can't figure it out.
I legitimately cannot figure out what is wrong with this code.
Would appreciate help!
Server main class code : https://pastebin.com/4BS9qwHV
Client main class code : https://pastebin.com/v4vE108Z
(Code in pastebin because it was too long)
Server output :
run:
===================================
Welcome to the game of Battleship!
===================================
Type "rules" if you don't know the rules.
Type "pvp" if you want to play against another player via network connectivity!
Type "quit" if you want to quit the game.
pvp
Connect your client.
Socket Opened
Place your ships...
1 2 3 4 5 6 7 8 9 10
A - - - - - - - - - -
B - - - - - - - - - -
C - - - - - - - - - -
D - - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place a ship?
Remaining to place: 5
a1
What type of ship? Sizes - 1, 2, 3, 4, 5
1
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B - - - - - - - - - -
C - - - - - - - - - -
D - - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place a ship?
Remaining to place: 4
b1
What type of ship? Sizes - 1, 2, 3, 4, 5
1
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B X - - - - - - - - -
C - - - - - - - - - -
D - - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place a ship?
Remaining to place: 3
c1
What type of ship? Sizes - 1, 2, 3, 4, 5
1
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B X - - - - - - - - -
C X - - - - - - - - -
D - - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place a ship?
Remaining to place: 2
d1
What type of ship? Sizes - 1, 2, 3, 4, 5
1
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B X - - - - - - - - -
C X - - - - - - - - -
D X - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place a ship?
Remaining to place: 1
e2
What type of ship? Sizes - 1, 2, 3, 4, 5
1
Direction?
1
Ready to move on?
ready
ready198
Exception in thread "main" java.lang.NullPointerException
at battleship.Battleship.startPVP2(Battleship.java:200)
at battleship.Battleship.startPVP(Battleship.java:131)
at battleship.Battleship.intro(Battleship.java:47)
at battleship.Battleship.main(Battleship.java:20)
~/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 39 seconds)
Client output :
run:
===================================
Welcome to the game of Battleship!
===================================
Type "rules" if you don't know the rules.
Type "pvp" if you want to play against another player via network connectivity!
Type "quit" if you want to quit the game.
pvp
Establishing Connection
Connecting
...Successful connection to server!
Place your ships...
1 2 3 4 5 6 7 8 9 10
A - - - - - - - - - -
B - - - - - - - - - -
C - - - - - - - - - -
D - - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place the ship of size2?
a1
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B X - - - - - - - - -
C - - - - - - - - - -
D - - - - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place the ship of size3?
b3
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B X - X - - - - - - -
C - - X - - - - - - -
D - - X - - - - - - -
E - - - - - - - - - -
F - - - - - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place the ship of size4?
c4
Direction?
1
1 2 3 4 5 6 7 8 9 10
A X - - - - - - - - -
B X - X - - - - - - -
C - - X X - - - - - -
D - - X X - - - - - -
E - - - X - - - - - -
F - - - X - - - - - -
G - - - - - - - - - -
H - - - - - - - - - -
I - - - - - - - - - -
J - - - - - - - - - -
Where would you like to place the ship of size5?
a7
Direction?
1
220Successful connection to server!
Exception in thread "main" java.lang.NullPointerException
at battleshipmyclient.Battleship.startPVP2(Battleship.java:219)
at battleshipmyclient.Battleship.startPVP(Battleship.java:143)
at battleshipmyclient.Battleship.intro(Battleship.java:46)
at battleshipmyclient.Battleship.main(Battleship.java:19)
~/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 39 seconds)