我是java的新手
这是我的第一个真实项目(纸牌游戏:二十一点)
我做了一个测试课,并被告知要使用打印行试图找出我的问题,但是我无法理解为什么null异常不断出现.我没有任何设置为null,并且我的数组已使用"new"初始化.我也可以发布IO类,但我相当肯定问题不在其中.
public static void main(String[] args) {
// Initializing just a single player
Player x = new Player();
// Quick test to make sure it reads the initial value of 0
System.out.println(x.getMoney());
// Testing user input using an IO class given
System.out.println("How much would you guys like to play with?(Bet money)");
double y = IO.readDouble();
x.addMoney(y);
System.out.println(x.getMoney());
// Successfully prints out the value y
Player[] total = new Player[4];
total[1].addMoney(y);
System.out.println(total[1].getMoney());
// returns the null pointer exception error …Run Code Online (Sandbox Code Playgroud) 通过Microsoft文档和完成教程,我目前正在研究类和对象模块.
using System;
namespace classes
{
public class BankAccount
{
public string Number { get; }
public string Owner { get; set; }
public decimal Balance { get; }
public BankAccount(string name, decimal initialBalance)
{
this.Owner = name;
this.Balance = initialBalance;
}
public void MakeDeposit(decimal amount, DateTime date, string note)
{
}
public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
}
}
Run Code Online (Sandbox Code Playgroud)
}
是我们开始的,我将调用此类作为Program.cs文件中的测试
using System;
namespace classes
{
public class Program
{
var account = new BankAccount("<HAMID>", 1000); …Run Code Online (Sandbox Code Playgroud)