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 7088561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:48:58+00:00 2026-05-28T07:48:58+00:00

I have been working on a program and when I run it I get

  • 0

I have been working on a program and when I run it I get an error that says line 43 and 84 have a NullPointerException. This is the code. I have put comments where line 43 and 84 are. I am trying to make a word processor like Microsoft Word.

import javax.swing.*;
import java.awt.*;

public class Graphics {
    // listing all the components 
    JFrame f1;
    JPanel colorspanel;
    JPanel sizepanel;
    JPanel fontpanel;
    JPanel mainpanel;
    JTextField Maintextfield;
    JLabel colorlabel;
    JLabel sizelabel;
    JLabel fontlabel;
    JButton colorbuttons[];
    JButton sizebuttons[];
    JButton fontbuttons[];

    Graphics() {
        // making instances of panels
        colorspanel = new JPanel();
        sizepanel = new JPanel();
        fontpanel = new JPanel();
        mainpanel = new JPanel();
        // setting the size of the panels
        colorspanel.setSize(216, 144);
        sizepanel.setSize(216, 144);
        fontpanel.setSize(216, 144);
        mainpanel.setSize(612, 756);    
        // making instances of button
        colorbuttons = new JButton[9];
        sizebuttons = new JButton[14];
        fontbuttons = new JButton[9];
        // setting content for buttons
        // colorbuttons
        colorbuttons[0].setBackground(Color.black);//line 43
        colorbuttons[1].setBackground(Color.red);
        colorbuttons[2].setBackground(Color.blue);
        colorbuttons[3].setBackground(Color.yellow);
        colorbuttons[4].setBackground(Color.green);
        colorbuttons[5].setBackground(Color.gray);
        colorbuttons[6].setBackground(Color.DARK_GRAY);
        colorbuttons[7].setBackground(Color.ORANGE);
        colorbuttons[8].setBackground(Color.pink);
        colorbuttons[9].setBackground(Color.magenta);
        // sizebuttons
        sizebuttons[0].setText("8");
        sizebuttons[1].setText("10");
        sizebuttons[2].setText("12");
        sizebuttons[3].setText("14");
        sizebuttons[4].setText("16");
        sizebuttons[5].setText("18");
        sizebuttons[6].setText("20");
        sizebuttons[7].setText("22");
        sizebuttons[8].setText("24");
        sizebuttons[9].setText("26");
        sizebuttons[10].setText("28");
        sizebuttons[11].setText("30");
        sizebuttons[12].setText("32");
        sizebuttons[13].setText("34");
        sizebuttons[14].setText("36");
        // fontbuttons
        fontbuttons[0].setText("New Times Roman");
        fontbuttons[1].setText("Blackadder ITC");
        fontbuttons[2].setText("Andy");
        fontbuttons[3].setText("Buxton Sketch");
        fontbuttons[4].setText("Arial Black");
        fontbuttons[5].setText("Comic Sans MS");
        fontbuttons[6].setText("Old English Text MT");
        fontbuttons[7].setText("SketchFlow Print");
        fontbuttons[8].setText("Harlow Solid Italic");
        fontbuttons[9].setText("Algerian");
        f1.setVisible(true);
    }

    public static void main(String[] args){
        Graphics graphics = new Graphics();//line 84

    }

}
  • 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-05-28T07:48:58+00:00Added an answer on May 28, 2026 at 7:48 am

    You created an array, but you never populated it with anything. You need to put buttons in the array. A NullPointerException means that you tried to reference something, but a null value was found, not an object with a method or property. For example

    Object x = null;
    x.toString();  // NPE
    

    vs

    Object x = new Object();
    x.toString(); // we're in business
    

    In your case, you created an array (over 2 lines; just create everything on one line IMHO), but never put the buttons in it. So when you call colorButtons[0].whatever you are trying to access whatever on the reference at index 0. But since you didn’t put anything in the array, that reference is null.

    Do something more like

    JButton[] colorButtons = new JButton[9]; // initialize array
    for (int i = 0; i < colorButtons.length; i++) {
       JButton button = ... // initialize button each time thru
    
       // do any common setup on the buttons
    
       colorButtons[i] = button; // put the button in the array.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
I have been working on this code but I can't find out what is
I have been working on a childish little program: there are a bunch of
I have been working with a string[] array in C# that gets returned from
I have been working on a wrapper for a COM object that can only
I have a .NET project that's always been built/run by/on 32 bit machines. I
I have written a fairly large program in Fortran 90. It has been working
I've been working on this issue for a couple days and have read several
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)

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.