javadoc:error - 为类创建javadoc时的java.lang.NullPointerException

时间:2017-09-16 16:56:10

标签: java nullpointerexception javadoc

我已经制作了一个只有一个类的小程序,该程序工作正常,没有错误或警告,但是当我尝试从它创建javadoc时我得到了这个错误

  

javadoc:error - java.lang.NullPointerException

这是类源代码:

import javax.swing.*;
import java.util.*;


/** 
* This class represent each player in the game. 
* <p>
* Most of the methods and algorithms in <b>ProjectOOPDS</b> class are based on this class.
* <p>
* This class shows the hands of the players, win counts, scores and resets the values 
* for each player, in each round and each game.
*
*
*@see ProjectOOPDS
**@since 2017-09-17
*/
class Player
{ 
    public String player = "";
    public int winCount = 0;
    public String[] hand = new String[3]; 
    public int points = 0;
    public int totalPoints = 0;

    private String h = " ";

    public Player(){}
    public Player(String player){
        this.player = player;
        this.winCount = winCount;

    }
    /** show the players' hand.*/
    public String showHand(){ 
        return player + " cards: " + viewHand();
    }
    /** shows how many times the player has won.*/
    public String showWinCount(){ 
        return player + " = " + winCount;
    }
    /** used for the other players that did not win.*/
    public String showScore(){ 
        return " |  " + "Sum = " + (points%10);
    }
     /** used for the player that has won the round.*/
    public String showScoreWinner(){
        return " |  " + "Sum = " +  (points%10) + "  | " + " Winner";
    }
    /** reset for rounds.*/
    public void reset(){ 
        points = 0;
        Arrays.fill(hand, null);
        h = " ";
    }
    /** when tie in <b>ProjectOOPDS</b> class.*/
    public String tie(){ 
        return player + " Total points(non-Rightmost digit): " + totalPoints;
    }
    /** reset for game. */
    public void resetGame(){ 
        reset();
        winCount = 0;
        totalPoints = 0;
    }
    /** get the hand to show in showHand().*/
    private String viewHand(){ 
        for(String s: hand){
            h = h + (s + " ");
        }
        return h;

    }
}

我试图从主要课程制作javadoc并且它有效,但我不知道为什么这个没有工作。

谢谢。

1 个答案:

答案 0 :(得分:-1)

我自己修复了它,显然当你想要javadoc时,你的代码不能有任何null值,它在编译时会正常工作但javadoc不是这种情况。我的代码中有一个空值,因此需要对此进行更改:

public void reset(){ 
        points = 0;
        Arrays.fill(hand, null);
        h = " ";
    }

到此:

public void reset(){ 
        points = 0;
        Arrays.fill(hand, " ");
        h = " ";
    }

就是这样!错误应该是固定的。