Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:37:05+00:00 2026-06-03T19:37:05+00:00

I’m trying to create a list as below in Java. Maybe I’m naive to

  • 0

I’m trying to create a list as below in Java. Maybe I’m naive to OOP and Java, therefore I’m not able to resolve it.

I need to create a below table

Character Count Price
   A       1      2
   B       1      12
   C       1      1.25
   D       1      0.15
   A       4      7
   C       6      6

I have create a class as below:

class ProductList {
    private char ProductName;
    private double Price;
    private int Count;  

    public char getProductName() {
    return ProductName;
}
public void setProductName(char productName) {
    ProductName = productName;
}
public double getPrice() {
    return Price;
}
public void setPrice(double price) {
    Price = price;
}
public int getCount() {
    return Count;
}
public void setCount(int count) {
    Count = count;
}
}

Then comes my main class which create the list of the product table as above.

public class ProductEntryList {
     public static void main(String[] args) {
        ProductList[] entry = new ProductList[6];
        //Product Entry for A
        entry[0].setProductName('A');
        entry[0].setCount(1);
        entry[0].setPrice(2);

            //Similarly for other entries of product

        for(int loop = 0;loop<entry.length;loop++) {
            System.out.print(entry[loop].getProductName()+" ");
            System.out.print(entry[loop].getCount()+" ");
            System.out.print(entry[loop].getPrice()+"\n");
        }
    }
}

I’m quite bugged why I m getting

    Exception in thread "main" java.lang.NullPointerException
    at ProductEntryList.main(ProductEntryList.java:13)

Any input this would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:37:06+00:00Added an answer on June 3, 2026 at 7:37 pm

    Nullpointerexception is thrown when you use dot(.) operator on null reference.

    As I can see, In the first line of your main method,

    ProductList[] entry = new ProductList[6];
    

    You are only initializing the array, and not initializing the product list entries in the array. So the array contains null entries.

    You need to add following code after that line:

    for(int i=0;i<entry.size();i++)
    {
        entry[i]=new ProductList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.