This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I keep getting this error in my code. Can someone fix it and how is the code written? Can it be improved by maybe using setters and getters only?
Exception in thread "main" java.lang.NullPointerException
at Player.attack(Player.java:72)
at Main.main(Main.java:15)
My code:
Player.java
public class Player {
String name;
String race;
int hp;
int power;
int armour;
Weapon weapon;
public Player (String n, String r, int h, int p, int a) {
name = n;
race =r;
hp = h;
power = p;
armour = a;
}
public void setName (String n) {
name = n;
}
public String getName() {
return name;
}
public void setRace (String r) {
race = r;
}
public String getRace() {
return race;
}
public void setHP (int h) {
hp = h;
}
public int getHP() {
return hp;
}
public void setPower (int p) {
power = p;
}
public int getPower() {
return power;
}
public void setArmour (int a) {
armour = a;
}
public int getArmour() {
return armour;
}
public boolean dead() {
return hp <= 0;
}
public boolean equip(Weapon weapon) {
this.weapon = weapon;
return true;
}
public boolean receiveDamage(int i) {
if ((hp - i) > 0) {
hp = hp - i;
return true;
}
hp = 0;
return false;
}
public boolean attack(Player player) {
return player.receiveDamage(weapon.useWeapon());
}
}
Main.java
public class Main {
public static void main(String args[]) {
Player Mensch = new Player("Mensch", "Mensch", 85, 12, 10);
Player Ork = new Player("Shrek", "Ork", 50, 14, 6);
Weapon MenschW = new Weapon("mächtiges Schwert", 15, 100);
Weapon OrkW = new Weapon("große Axt", 7, 100);
Mensch.equip(Mensch.weapon);
Ork.equip(Ork.weapon);
while (!Mensch.dead() && !Ork.dead() ) { //Alternativ: for (player hp >=0)
System.out.println("Mensch gegen Ork " + Mensch.attack(Ork));
if (Mensch.dead() || Ork.dead()) {
break;
}
System.out.println("Mensch gegen Ork " + Ork.attack(Mensch));
}
System.out.println("Ork ist tot: " + Ork.dead());
System.out.println("Mensch ist tot: " + Mensch.dead());
}
}
Weapon.java
import java.util.concurrent.ThreadLocalRandom;
public class Weapon {
String name;
int damage;
int hp;
public Weapon(String string, int d, int hp) {
// TODO Auto-generated constructor stub
}
public void setName (String n) {
name = n;
}
public String getName() {
return name;
}
public void setDamage (int d) {
damage = d;
}
public int getDamage() {
return damage;
}
public void setWHP (int h) {
hp = h;
}
public int getWHP() {
return hp;
}
public int useWeapon() {
if
(broken())
return 0;
hp = hp - 5;
return (damage / 2) + random();
}
private int random() {
return ThreadLocalRandom.current().nextInt(1, damage + 1);
}
private boolean broken() {
return hp <= 0;
}
}
I know its a lot of code but I keep getting the same error, also I'm quite new to java so I would appreciate some tips or suggestions to make my code better or more failsave. The code doesn't do much yet but it will (hopefully) be a simple game soon in which two characters fight eachother with some calculations on damageoutput of each player. In this case a Human and Ork. Feel free to try it out
Change
Mensch.equip(Mensch.weapon); // Mensch.weapon is not initialized in constructor so it is null.
Ork.equip(Ork.weapon); // Ork.weapon is not initialized in constructor so it is null as well.
To
// Use your newly created weapons in the main instead.
Mensch.equip(MenschW );
Ork.equip(OrkW);
Related
I have two classes called Pokemon.java and Move.java which contain methods for creating and modifying Pokemon and their moves. I've created all of the required methods, but I'm having trouble with the attack method, which is supposed to subtract an opponent's health when it's attacked.
Here is the code for the Pokemon.java class:
import java.util.ArrayList;
public class Pokemon
{
// Copy over your code for the Pokemon class here
// Private constants
private static final int MAX_HEALTH = 100;
private static final int MAX_MOVES = 4;
private String name;
private int health;
private int opponentHealth;
public static int numMovesForPokemon = Move.getNumOfMoves();
private Move move;
private static ArrayList<Move> moveListForPokemon = new ArrayList<Move>();
private String pokemonImage;
// Write your Pokemon class here
public Pokemon(String theName, int theHealth)
{
name = theName;
if(theHealth <= MAX_HEALTH)
{
health = theHealth;
}
}
public Pokemon(String name, String image)
{
this.name = name;
health = 100;
pokemonImage = image;
}
public Pokemon(String theName)
{
name = theName;
}
public void setImage(String image)
{
pokemonImage = image;
}
public String getImage()
{
return pokemonImage;
}
public String getName()
{
return name;
}
public int getHealth()
{
return health;
}
public boolean hasFainted()
{
if(health <= 0)
{
return true;
}
else
{
return false;
}
}
public boolean canLearnMoreMoves()
{
if(numMovesForPokemon < 4)
{
return true;
}
else
{
return false;
}
}
public boolean learnMove(Move other)
{
if(canLearnMoreMoves())
{
moveListForPokemon = Move.getList();
moveListForPokemon.add(other);
numMovesForPokemon++;
return true;
}
else
{
return false;
}
}
public void forgetMove(Move other)
{
moveListForPokemon.remove(other);
}
public static ArrayList<Move> displayList()
{
return moveListForPokemon;
}
public boolean knowsMove(Move move)
{
if(moveListForPokemon.contains(move))
{
return true;
}
else
{
return false;
}
}
public boolean knowsMove(String moveName)
{
if(moveListForPokemon.contains(move.getName()))
{
return true;
}
else
{
return false;
}
}
public boolean attack(Pokemon opponent, Move move)
{
if(knowsMove(move))
{
opponentHealth = opponent.getHealth();
opponentHealth -= move.getDamage();
return true;
}
else
{
return false;
}
}
public boolean attack(Pokemon opponent, String moveName)
{
if(knowsMove(moveName))
{
opponentHealth = opponent.getHealth();
opponentHealth -= move.getDamage();
return true;
}
else
{
return false;
}
}
public String toString()
{
return pokemonImage + "\n" + name + " (Health: " + health + " / " + MAX_HEALTH + ")";
}
// Add the methods specified in the exercise description
}
Here is the code for the Move.java class:
import java.util.ArrayList;
public class Move
{
// Copy over your code for the Move class here
private static final int MAX_DAMAGE = 25;
private String name;
private int damage;
public static int numMoves;
private static ArrayList<Move> moveList = new ArrayList<Move>();
public Move(String theName, int theDamage)
{
name = theName;
if(theDamage <= MAX_DAMAGE)
{
damage = theDamage;
}
}
public String getName()
{
return name;
}
public int getDamage()
{
return damage;
}
public static int getNumOfMoves()
{
return numMoves;
}
public static ArrayList<Move> getList()
{
return moveList;
}
public String toString()
{
return name + " (" + damage + " damage)";
}
// Add an equals method so we can compare Moves against each other
public boolean equals(Move other)
{
if(name.equals(other.getName()))
{
return true;
}
else
{
return false;
}
}
}
Finally, here is the code for PokemonTester.java where I test out the methods:
public class PokemonTester extends ConsoleProgram
{
private PokemonImages images = new PokemonImages();
public void run()
{
// Test out your Pokemon class here!
Pokemon p1 = new Pokemon("Charrizard", 100);
Pokemon p2 = new Pokemon("Pikachu", 100);
Move m1 = new Move("Flamethrower", 20);
Move m2 = new Move("Fire Breath", 15);
p1.learnMove(m1);
System.out.println(p1.knowsMove(m1));
System.out.println(p1.knowsMove("Flamethrower"));
System.out.println(p1.attack(p2, m1));
System.out.println(p2.getHealth());
}
}
I suppose your problem is this:
opponentHealth = opponent.getHealth();
opponentHealth -= move.getDamage();
This code has several problems:
I'd suggest using a local variable for opponentHealth instead of a class level field
The opponent doesn't gets to know that it's health was subtracted. You have to share this knowledge with him, e.g. by introducing a setter for health and then calling opponent.setHealth(opponentHealth)
You are first assigning the value of Oponent.getHealth() to the int variable oponentHealth which you then modify, however this modification does not affect the health of Opponent but instead just the oponentHealth variable, you either have to directly access and modify the health field of Opponent or implement some kind of setHealth(int health) method in the class Pokemon
My question is if it possible to use a void method in a setText for a Label? I'm working at the moment on school homework on Netbeans and I want to use the 'public void printTable()' in a Label but the programm always say that it is impossible to use a void here and I know that normally I should use a return statement but in the instruction is written that I should use a 'void'.
Here you can see my Java Class
public class AffineFunction
{
private int a;
private int b;
public int getA()
{
return a;
}
public int getB()
{
return b;
}
public void setA(int newA)
{
a = newA;
}
public void setB(int newB)
{
b = newB;
}
public AffineFunction(int pA, int pB)
{
a = pA;
b = pB;
}
public int solve(int x)
{
return (a*x)+b;
}
public void printTable()
{
for(int i =-10; i<=10; i++)
{
System.out.println("F(" + i + ") = " + solve(i));
}
}
public void printTable(double step)
{
for(double i = - 10 ; i<= 10; i = i + step)
{
System.out.println( "F(" + i + ") = " + solve((int)i));
}
}
}
Here is a part of my JFrame :
//E
int a = Integer.valueOf(aTextField.getText());
int b = Integer.valueOf(bTextField.getText());
int x = Integer.valueOf(xTextField.getText());
//T
AffineFunction affineFunction = new AffineFunction(a, b);
//S
FLabel.setText(String.valueOf(affineFunction.solve(x)));
printTableLabel.setText(String.valueOf(affineFunction.printTable()));
I'm trying to make a tic tac toe game, and it works fine when the first X or O is inputted, but when the second is inputted the previous X or O is deleted and the new one is put in. I have no idea why this is happening.
import java.util.Scanner;
public class Play {
public static void main(String[] args){
Scanner kbd=new Scanner(System.in);
TicTacToeBoard t=new TicTacToeBoard(3, 3);
t.startBoard();
XO xo1=new XO();
xo1.setTurns(1);
XO xo2=new XO();
xo2.setTurns(0);
System.out.println("Player 1, what is your name?");
String n1=kbd.nextLine();
System.out.println("Player 2, what is your name?");
String n2=kbd.nextLine();
System.out.println(t);
while(!t.winner()&&!t.full()){
if(t.getTurnCnt()%2==0){
System.out.println(n1+"(X): ");
int x1=kbd.nextInt();
int y1=kbd.nextInt();
t.add(x1, y1, xo1);
System.out.println(t);
}
//this is where the board resets
else{
System.out.println(n2+"(O): ");
int x2=kbd.nextInt();
int y2=kbd.nextInt();
t.add(x2, y2, xo2);
System.out.println(t);
}
TicTacToeBoard Class:
public class TicTacToeBoard extends Board{
private XO[][] board;
private int turnCnt;
public TicTacToeBoard(int r, int c){
super(r, c);
board=new XO[r][c];
turnCnt=0;
}
public void startBoard(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
board[i][j]=new XO();
board[i][j].setName("-");
}
}
}
public void setTurnCnt(int t){
turnCnt=t;
}
public XO[][] setBoard(XO[][] b){
return b;
}
public XO[][] getBoard(){
return board;
}
public int getTurnCnt(){
return turnCnt;
}
public boolean add(int x, int y, XO x1){
if(x<=this.getRows()&&y<=this.getCols()&&(board[x-1][y-1].getName().equals("-"))){
board[x-1][y-1].setName(x1.getName());
turnCnt++;
return true;
}
else
System.out.println("error");
return false;
}
public boolean winner(){
boolean t=false;
for(int i=0;i<3;i++){
if(board[i][0].equals(board[i][1], board[i][2])||board[0][i].equals(board[1][i], board[2][i])||board[0][0].equals(board[1][1], board[2][2])||board[2][0].equals(board[1][1], board[0][2]))
t=true;
}
return t;
}
public boolean XWinner(){
boolean t=false;
for(int i=0;i<3;i++){
if((board[i][0].equals(board[i][1], board[i][2])&&board[i][1].getName().equals("X"))||(board[0][i].equals(board[1][i], board[2][i])&&board[0][i].getName().equals("X"))||(board[0][0].equals(board[1][1], board[2][2])&&board[0][0].getName().equals("X"))||(board[2][0].equals(board[1][1], board[0][2])&&board[2][0].getName().equals("X")))
t=true;
}
return t;
}
public boolean full(){
boolean t=true;
for(int r=0;r<3;r++){
for(int c=0;c<3;c++){
if(board[r][c].getName()=="-")
t=false;
}
}
return t;
}
public String toString(){
return "\t\t\tCol\n\t\t1\t2\t3\nRow\t1\t"+board[0][0]+"\t"+board[0][1]+"\t"+board[0][2]+"\n\t2\t"+board[1][0]+"\t"+board[1][1]+"\t"+board[1][2]+"\n\t3\t"+board[2][0]+"\t"+board[2][1]+"\t"+board[2][2];
}
}
XO class:
public class XO {
private String name;
private int turn;
public XO(){
turn=-1;
}
public int getTurns(){
return turn;
}
public String getName(){
if(this.getTurns()==1)
name="X";
else if(this.getTurns()==0)
name="O";
else
name="-";
return name;
}
public void setName(String n){
name=n;
}
public void setTurns(int t){
turn=t;
}
public boolean equals(XO x1, XO x2){
if (x1.getName().equals(this.getName())&&x2.getName().equals(this.getName())&&this.getName()!="-")
return true;
else
return false;
}
public String toString(){
return name;
}
}
The problem is on your function
public String getName(){
if(this.getTurns()==1)
name="X";
else if(this.getTurns()==0)
name="O";
else
name="-";
return name;
}
Every time is called the name field is updated despite it is a getter method! This is not a best practice.
Let's go step by step:
the user gives his coordinates.
the name is set to the correct value: "X" or "O"
the board is printed (calling XO.toString (using name field direct
no through any getter
The status of the board is evaluated using the getName getter and
now is when the name got back to "-" because the turn has not been
changed.
Finally, I think that you can simplify XO class. Turn field does not add any worth. It seems enough to use the name field itself. And the if statement is redundant because the boolean expression inside the if is just what you want to return.
class XO {
String name="-";
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public boolean equals(XO x1, XO x2){
return(x1.getName().equals(this.getName())&&x2.getName().equals(this.getName())&&this.getName()!="-");
}
#Override
public String toString() {
return getName();
}
}
As an example, this can be the final code. Notice that more refactor can be done i.e. use an enum for XO status.
import java.util.Scanner;
public class Play {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
TicTacToeBoard t = new TicTacToeBoard(3, 3);
t.startBoard();
XO xo1 = new XO();
xo1.setName("O");
XO xo2 = new XO();
xo2.setName("X");
System.out.println("Player 1, what is your name?");
String n1 = kbd.nextLine();
System.out.println("Player 2, what is your name?");
String n2 = kbd.nextLine();
System.out.println(t);
while (!t.winner() && !t.full()) {
if (t.getTurnCnt() % 2 == 0) {
System.out.println(n1 + "(X): ");
int x1 = kbd.nextInt();
int y1 = kbd.nextInt();
t.add(x1, y1, xo1);
System.out.println(t);
}
//this is where the board resets
else {
System.out.println(n2 + "(O): ");
int x2 = kbd.nextInt();
int y2 = kbd.nextInt();
t.add(x2, y2, xo2);
System.out.println(t);
}
}
}
}
class TicTacToeBoard {
private XO[][] board;
private int turnCnt;
public TicTacToeBoard(int r, int c){
board=new XO[r][c];
turnCnt=0;
}
public void startBoard(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
board[i][j]=new XO();
board[i][j].setName("-");
}
}
}
public void setTurnCnt(int t){
turnCnt=t;
}
public XO[][] setBoard(XO[][] b){
return b;
}
public XO[][] getBoard(){
return board;
}
public int getTurnCnt(){
return turnCnt;
}
public boolean add(int x, int y, XO x1){
if(x<=this.getRows()&&y<=this.getCols()&&(board[x-1][y-1].getName().equals("-"))){
board[x-1][y-1].setName(x1.getName());
turnCnt++;
return true;
}
else
System.out.println("error");
return false;
}
public boolean winner(){
boolean t=false;
for(int i=0;i<3;i++){
if(board[i][0].equals(board[i][1], board[i][2])||board[0][i].equals(board[1][i], board[2][i])||board[0][0].equals(board[1][1], board[2][2])||board[2][0].equals(board[1][1], board[0][2]))
t=true;
}
return t;
}
public boolean XWinner(){
boolean t=false;
for(int i=0;i<3;i++){
if((board[i][0].equals(board[i][1], board[i][2])&&board[i][1].getName().equals("X"))||(board[0][i].equals(board[1][i], board[2][i])&&board[0][i].getName().equals("X"))||(board[0][0].equals(board[1][1], board[2][2])&&board[0][0].getName().equals("X"))||(board[2][0].equals(board[1][1], board[0][2])&&board[2][0].getName().equals("X")))
t=true;
}
return t;
}
public boolean full(){
boolean t=true;
for(int r=0;r<3;r++){
for(int c=0;c<3;c++){
if(board[r][c].getName()=="-")
t=false;
}
}
return t;
}
public String toString(){
return "\t\t\tCol\n\t\t1\t2\t3\nRow\t1\t"+board[0][0]+"\t"+board[0][1]+"\t"+board[0][2]+"\n\t2\t"+board[1][0]+"\t"+board[1][1]+"\t"+board[1][2]+"\n\t3\t"+board[2][0]+"\t"+board[2][1]+"\t"+board[2][2];
}
public int getRows() {
return 3;
}
public int getCols() {
return 3;
}
}
class XO {
String name="-";
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public boolean equals(XO x1, XO x2){
return(x1.getName().equals(this.getName())&&x2.getName().equals(this.getName())&&this.getName()!="-");
}
#Override
public String toString() {
return getName();
}
}
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
I just cannot figure out why this keeps pointing to null. I am a fairly new programmer. But here I have made a Dice class and a commands class.
I have tried changing variables and all sorts of stuff. I guess I'm just not sure why it's pointing to null.
package com.rs.game.player;
/**
* Created by Kevinpro0 on 2/26/2015.
*/
public class Dice {
public int die2;
public int die3;
public int die4;
public int die6;
public int die8;
public int die10;
public int die12;
public int die14;
public int die16;
public int die18;
public static int die20;
public void d2() {
die2 = (int)(Math.random()*2) +1;
}
public void d3() {
die3 = (int)(Math.random()*3) +1;
}
public void d4() {
die4 = (int)(Math.random()*4) +1;
}
public void d6() {
die6 = (int)(Math.random()*6) +1;
}
public void d8() {
die8 = (int)(Math.random()*8) +1;
}
public void d10() {
die10 = (int)(Math.random()*10) +1;
}
public void d12() {
die12 = (int)(Math.random()*12) +1;
}
public void d14() {
die14 = (int)(Math.random()*14) +1;
}
public void d16() {
die16 = (int)(Math.random()*16) +1;
}
public void d18() {
die18 = (int)(Math.random()*18) +1;
}
public static int d20() {
die20 = (int)(Math.random()*20) +1;
return die20;
}
}
/***** i am ONLY using d20 for this right now...****/
DM.java
package com.rs.game.player;
import com.rs.game.player.*;
import com.rs.game.World;
import java.util.Arrays;
/**
* Created by Kevinpro0 on 3/1/2015.
*/
public class Dm {
public static Dice init = new Dice();
public static int worldSize = World.getPlayers().size();
public static int[] PlayerInt = new int[worldSize];
//
public static Player player;
public static int initRoll = init.die20;
public static String playersName;
public static int i = 1;
public static void initiative(){
for (i = 1; i < World.getPlayers().size() + 1; i++) {
//Dice = new Dice();
init.d20();
PlayerInt[i] = initRoll;
player.getPackets().sendPanelBoxMessage(Integer.toString(Dice.d20()));
//player.getPackets().sendPanelBoxMessage("Player " + i + " is " + playersName + " and initiative roll: " + Integer.toString(initRoll));
}
}
}
Commands.java
case "init":
case "initiative":
Dm dmaster = new Dm();
//String currentPlayer = player.getUsername();
//Player Dm = World.getPlayerByDisplayName("Dm");
if (player.getUsername().equalsIgnoreCase("Dm")) {
if (World.getPlayers().size() <= 1){
player.getPackets().sendPanelBoxMessage("Not enough players logged in.");
} else {
Dm.initiative();
player.getPackets().sendPanelBoxMessage(Dm.playersName + " and initiative roll: " + Integer.toString(Dm.initRoll));
}
}
return true;
In this line public static int initRoll = init.die20; you are referring to the value of 'die20', but it is not set until much later, in the for loop, when you say init.d20(). I hope that helps a little, though I think your code needs work in other areas too.
Ok I will try to make this clear as possible. I hope it doesn't get flagged before I get an answer.
I am trying to serialize a class for saving which works just fine. But some of the variables are not getting loaded correctly. Here is the code:
I also marked out places where the code is working and not working.
EDIT: Simplified code a bit more.
Class im saving: (Simple version of it)
public class classToSave implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5184436214950145051L;
public static List<classToSave> classtosavelist = new ArrayList<classToSave>();
public static classToSave one = new OtherClass1("1", 1, 1, null, Item.1, 1);
public static classToSave two = new OtherClass1("2", 1, 2, one , Item.2, 1);
public static classToSave three = new OtherClass2("3", 1, 4, two , Item.3, 2);
public boolean done = false; < WONT LOAD/SAVE
public int lvl = 0; < WONT LOAD/SAVE
transient protected String name; < OK
protected int Xpos; < OK
protected int Ypos; < OK
public Skill parent; < OK
protected Item item; < OK
public int extra = 0; < OK (This Works..)
public classToSave(String s, int x, int y, Skill parent, Item item, int cost) {
this.name = s;
this.Xpos = x;
this.Ypos = y;
if(parent != null) {
this.Xpos += parent.Xpos;
this.Ypos += parent.Ypos;
}
this.parent = parent;
this.item = item;
add(this, s);
}
private void add(classToSave classtosave, String name) {
boolean flag = true;
for(int i = 0; i < skills.size(); i++) {
if(classtosavelist.get(i).getName().equalsIgnoreCase(name)) {
flag = false;
}
}
if(flag) {
classtosavelist.add(classtosave);
}
}
public int needPoints() {
return 1 + extra;
}
public boolean Done(int points) {
if(points >= needPoints()) {
this.done = true;
}
return this.done;
}
public int getLevel() {
return this.lvl;
}
public int MAXLevel() {
return 1;
}
public void LevelUp() {
if(this.lvl < MAXLevel()) {
this.lvl++;
}
}
public void Reset() {
this.lvl = 0;
}
public Item getRenderItem() {
return this.item;
}
public String getName() {
return this.name;
}
public Skill getParent() {
return this.parent;
}
public boolean isCompleteDone() {
return (getLevel() == MAXLevel() && done);
}
Here is the save and load:
private ClassToSave classtosave;
private void save(String savename) {
if (externalStorageWriteable) {
try {
File file = new File(ctxt.getExternalFilesDir(null), savename);
FileOutputStream fos = new FileOutputStream(file, false);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(classtosave);
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void load(String savename) throws ClassNotFoundException, StreamCorruptedException, IOException {
if (externalStorageAvailable) {
File file = new File(ctxt.getExternalFilesDir(null), savename);
FileInputStream fis = new FileInputStream(file);
ObjectInputStream is = new ObjectInputStream(fis);
ClassToSave classtosave = (ClassToSave) is.readObject();
for (int i=0; i < classtosave.classtosavelist.size(); i++) {
classtosave.classtosavelist.get(i).Done(classtosave.classtosavelist.get(i).needPoints()); < WORKS
classtosave.classtosavelist.get(i).isCompleteDone(); < DOENST WORK
classtosave.classtosavelist.get(i).getLevel(); < DOESNT WORK
if (classtosave.classtosavelist.get(i).done == true){ <DOESNT WORK
classtosave.classtosavelist.get(i).done = true;
classtosave.classtosavelist.get(i).LevelUp();
}
}
}
is.close();
}
Sorry if brackets are out of place. This code was butchered(Renamed and modified) to make it more readable.
But basically this code is used for a "Skill tree" and what it is supposed to do is save if said skill is complete or not.
If this needs fixed let me know. I can also provide more code as needed.
Your constructor misses the boolean and the int. It should be like this :
public classToSave(boolean done, int lvl, String s, int x, int y, Skill parent, Item
item, int cost) {
this.done = done;
this.lvl = lvl;
...
}