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

  • Home
  • SEARCH
  • 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 7527675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:09:51+00:00 2026-05-30T04:09:51+00:00

I am writing a simulation Memory Manger and I was working with Jtables to

  • 0

I am writing a simulation Memory Manger and I was working with Jtables to display partition table. I had this working with another GUI. I recreated the GUI using a different layout style (absolute) with JPanel’s and now the code for creating my partiton table fails to initialize.

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import java.awt.Font;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.DefaultComboBoxModel;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;


public class mWindow extends JFrame {

private static final long serialVersionUID = 1L;

private final FixedMemory fpMemory = new FixedMemory(this);     // Fixed Partition Memory Scheme
private final Queue jobQueue = new Queue(this);                             // New Job Queue
public JTextField statusField;



public JComboBox<String> memScheme_cb;
public DefaultTableModel ptModel;

public List<Job> JobQueueList = new ArrayList<Job>();                       // Job Queue
public List<Partition> PartTableList = new ArrayList<Partition>();      // Partition Table



// Window Constructor
public mWindow() {

    // Setup Main Window ==================================================================
    getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 12));
    getContentPane().setLayout(null);

    // Set up the panel to hold control objects (buttons, Combo Box, Status Text Field
    // Setup Control Panel Area to contain buttons, Combo box and statusField ==========================
    JPanel controlPanel = new JPanel();
    controlPanel.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
    controlPanel.setBounds(10, 10, 490, 80);
    controlPanel.setLayout(null);

    getContentPane().add(controlPanel);

    // Setup statusField to update current Process ================================================
    statusField = new JTextField();
    statusField.setBounds(145, 46, 335, 23);
    statusField.setFont(new Font("Tahoma", Font.PLAIN, 12));
    statusField.setEditable(false);
    statusField.setBackground(new Color(240,240,240));
    statusField.setText("No Job Processes Running");                    // set initial message
    controlPanel.add(statusField);

    // Setup button to process memory scheme==================================================
    JButton btnProcScheme = new JButton("Process Memory");
    btnProcScheme.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            String memScheme = (String) memScheme_cb.getSelectedItem();
            if ( memScheme == "Fixed Memory" ){
                 statusField.setText("Fixed Memory");

                 // Call a fixed partition scheme and create Job Queue
                fpMemory.createPartition(PartTableList);
                jobQueue.createJobQueue();

            }else if ( memScheme == "Dynamic FirstFit" ){
                statusField.setText("Dynamic FirstFit" );

            }else if ( memScheme == "Dynamic BestFit" ){
                statusField.setText("Dynamic BestFit");

            }else if ( memScheme == "Dynamic WorstFit" ){
                statusField.setText("Dynamic WorstFit");

            } else if ( memScheme == ""){
                statusField.setText("No Memory Scheme Selected");

            }
        }
    });
    btnProcScheme.setBounds(10, 11, 125, 23);
    controlPanel.add(btnProcScheme);


    // Setup combo box to choose type of memory Scheme
    memScheme_cb = new JComboBox<String>();
    memScheme_cb.setBounds(145, 11, 335, 23);
    memScheme_cb.setModel(new DefaultComboBoxModel<String>(new String[]
            {"", "Fix Memory Partition", "Dynamic First Fit Partition", "Dynamic Best Fit Partition"}));
    memScheme_cb.setSelectedIndex(0);
    memScheme_cb.setMaximumRowCount(80);
    controlPanel.add(memScheme_cb);

    // Process Job Button==================================================================
    JButton btnProcJob = new JButton("Process Job Queue");
    btnProcJob.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // Call the Queue and process Jobs based on memory scheme
            jobQueue.procFixedJobQueue();
        }
    });
    btnProcJob.setBounds(10, 47, 125, 23);
    controlPanel.add(btnProcJob);


    // Setup Partition Table Area =============================================================
    JPanel tablePanel = new JPanel();
    tablePanel.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
    tablePanel.setBounds(10, 90, 490, 370);
    tablePanel.setLayout(null);
    getContentPane().add(tablePanel);

    JScrollPane partTable_sp = new JScrollPane();                                           // container to hold table
    getContentPane().add(partTable_sp);                                     // add container to layout
    partTable_sp.setBounds(15, 95, 480, 100);                           // sets where container is placed

    JTable partTable = new JTable(ptModel);                                         // create new table
    partTable.setPreferredScrollableViewportSize(new Dimension(480,100));   // set size of container
    partTable_sp.setViewportView(partTable);                                // show table in container


    ptModel.addColumn("Partition Size");                                        // add Columns to table
    ptModel.addColumn("Partition Address");                             //
    ptModel.addColumn("Access");                                                //
    ptModel.addColumn("Partition Status");                                  //

    TableColumn column = new TableColumn();                         // creates column variable

    // Sets up predefined column widths
    for (int i = 0 ; i < partTable.getColumnCount();i++){
        column = partTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(120);
    }


    // Setup snapshot Panel ================================================================
    JPanel snapPanel = new JPanel();
    snapPanel.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
    snapPanel.setBounds(500, 10, 120, 450);
    getContentPane().add(snapPanel);
    snapPanel.setLayout(null);

    Canvas snapFrame = new Canvas();
    snapFrame.setBounds(505, 15, 110, 440);
    snapFrame.setBackground(new Color(230,230,230));
    getContentPane().add(snapFrame);

}

// draw the segment of memory in the snapshot display at the address starting location
//      and the size of the memory segment (y value and the width are predetermined and are hard coded
public void displaySeg(Graphics g, int address, int size){
    g.setColor(new Color(245,245,245));
    g.drawRect(500,address+10, 120, size);
}



/**
 * @param args
 */
public static void main(String[] args) {

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                mWindow frame = new mWindow();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setTitle("Memory Manager v.01");
                Dimension windowSize = new Dimension(650,510);
                frame.setMinimumSize(windowSize);
                frame.pack();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}
}

The Stack Trace is:

java.lang.NullPointerException
at mWindow.<init>(mWindow.java:136)
at mWindow$3.run(mWindow.java:181)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

The code problem lies here????

        JTable partTable = new JTable(ptModel);                                         // create new table
    partTable.setPreferredScrollableViewportSize(new Dimension(480,100));   // set size of container
    partTable_sp.setViewportView(partTable);                                // show table in container


    ptModel.addColumn("Partition Size");                                        // add Columns to table
    ptModel.addColumn("Partition Address");                             //
    ptModel.addColumn("Access");                                                //
    ptModel.addColumn("Partition Status");                                  //

    TableColumn column = new TableColumn();                         // creates column variable

    // Sets up predefined column widths
    for (int i = 0 ; i < partTable.getColumnCount();i++){
        column = partTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(120);
    }

Sooo… line 136 is “ptModel.addColumn(“Partition Size”);” but for the life of me I can not see why it would fail (though I’m sure it is just something simple that I’ve overlooked)…Or maybe not. I’ve compared it with my original GUI code and it works fine. Any help would be greatly appreciatated!

  • 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-30T04:09:52+00:00Added an answer on May 30, 2026 at 4:09 am

    Nowhere can I see you actually setting up ptModel before trying to use it.

    It’s an object variable created with:

    public DefaultTableModel ptModel;
    

    and it’s first use is:

    JTable partTable = new JTable(ptModel);
    // blah blah blah
    ptModel.addColumn("Partition Size");
    ptModel.addColumn("Partition Address");
    ptModel.addColumn("Access");
    ptModel.addColumn("Partition Status");
    

    So it will still have its default value of null when you come to use it, hence the exception.

    You need to do a closer comparison with the older code. If it does the same thing, it wouldn’t work either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python newbie here: I'm writing a market simulation in Python using Pysage, and want
I'm writing a simulation in which a creature object should be able to move
I'm writing a simulation for class, and part of it involves the reproduction of
I am writing a simulation in Java whereby objects act under Newtonian physics. An
Right now I am writing a simulation program which output is formatted according to
I am writing a small simulation of a boat (a sailboat under power rather
I am writing a dhtml application that creates an interactive simulation of a system.
I'm writing a program in C++ to perform a simulation of particular system. For
Currently I am writing an iPad app. I am using a lot of images
I'm writing a programming language, and when I came across this question , my

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.