Word NullPointerException during program execution.
Catching an error on the products[i].getTitle() in the output method.
Most likely somewhere wrong with the links and the transfer of the array.
Please tell me where the problem is possible.
import java.util.Scanner; public class Main { public static void main(String[] args) { Deal deal = input(); output(deal); } public static Deal input(){ Scanner sc = new Scanner(System.in); System.out.println("Введите имя покупателя"); String buyerName = sc.next(); Party buyer = new Party(); buyer.setName(buyerName); System.out.println("Введите имя продавца"); String sellerName = sc.next(); Party seller = new Party(); seller.setName(sellerName); Product[] products = new Product[3]; for(Product i : products){ i=inputProduct(); } Deal deal = new Deal(buyer, seller, products); return deal; } public static Product inputProduct(){ Scanner sc = new Scanner(System.in); System.out.println("Введите описание продукта"); String title=sc.next(); System.out.println("Введите цену продукта"); double price=sc.nextDouble(); System.out.println("Введите количество продукта"); int quantity=sc.nextInt(); Product product = new Product(); product.setPrice(price); product.setTitle(title); product.setQuantity(quantity); return product; } public static void output(Deal deal){ String nameOfSeller=deal.getSeller().getName(); String nameOfBuyer=deal.getBuyer().getName(); Product[] products=deal.getProducts(); System.out.println("Deal " +deal.getDate() +" Имя продавца " +nameOfSeller +" Имя покупателя " +nameOfBuyer +":"); for(int i=0; i<products.length; i++){ System.out.println("Product " +products[i].getTitle() +" Цена " +products[i].getPrice() +" Количество " +products[i].getQuantity() +" Общая цена за продукт " +products[i].getCost()); } System.out.println("Общая стоимость сделки "+deal.getSum()); } } public class Party { private String name; public String getName(){ return this.name; } public void setName(String name){ this.name=name; } } public class Product { private String title; private double price; private int quantity; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; } public double getCost(){ return this.price*this.quantity; } } import java.util.Date; public class Deal { private Date date; private Party buyer; private Party seller; private Product[] products; public Deal(Party buyer,Party seller,Product[] products){ this.date=new Date(); this.buyer=buyer; this.seller=seller; this.products=products; } public double getSum(){ double rezult=0; for(Product i: this.products){ rezult+=i.getCost(); } return rezult; } public Party getBuyer(){ return this.buyer; } public Party getSeller(){ return this.seller; } public Date getDate(){ return this.date; } public Product[] getProducts(){ return this.products; } }