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

The Archive Base Latest Questions

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

I am currently doing a uni assignment as a fresher so I’m not very

  • 0

I am currently doing a uni assignment as a fresher so I’m not very experienced with coding.

The assignment is to allow the user to create a class diagram. Currently I have a secondary frame that the user inputs a UML design of the class in a JTextArea and then this should be passed through to my GUI by taking what the user wrote and drawing the string (drawString) onto the created class.

Currently I am getting a nullpointerexception when trying to get the String from the JTextArea to drawString and I don’t understand this because surely inputUML.getText() would be a String so should be able to be passed through?

This is the class that I am trying to pass the string into

package main;
import java.awt.*;
import javax.swing.*;
import classdesign.ClassCreation;



public class GroupCreateClass {
private double x;
private double y;
private double r;
private String message;
private String classdesign;


public GroupCreateClass(double x, double y, double r) {
    this.x = x;
    this.y = y;
    this.r = r;
}

public void draw(Graphics g) {
    makeRectangles(g);
    deleteBox(g);
    userdesignofclass(g);
}

public void makeRectangles(Graphics g) {

        g.drawRect((int)Math.round(x-r),(int)Math.round(y-r),
            (int)Math.round(325.0*r),(int)Math.round(350.0*r));

        g.drawRect((int)Math.round(x-r),(int)Math.round(y-r),
            (int)Math.round(325.0*r),(int)Math.round(19.5*r));

}

public void deleteBox(Graphics g) {

        g.fillRect((int)Math.round(x-r),(int)Math.round(y-r),
            (int)Math.round(19.5*r),(int)Math.round(19.5*r));
}

public void userdesignofclass(Graphics g){

    message = new String("Class");
    g.drawString(message,(int)Math.round(x+140),(int)Math.round(y+15));

    classdesign = (String.valueOf(inputUML.getText())); // This is the code that is giving me a nullpointerexception. I don't understand why, as surely inputUML.getText() should be a String...?
    g.drawString(classdesign,(int)Math.round(x+200), (int)Math.round(y+15));//
}


public double distanceTo(double x, double y) {
    return (Math.abs(this.x-x) + Math.abs(this.y-y));
}

public void update(double x, double y) {
    this.x = x;
    this.y = y;
}


}

This is the class that has the JTextArea, it is in another class and package, but the class that should be retrieving the string Extends this class.

 package classdesign;
 import java.awt.*;

 import javax.swing.*;

 public class ClassCreation extends JFrame {

private JFrame frame;
private JLabel instructionlabel;
protected JTextArea inputUML; //This is the JTextArea containing the text that I am trying to pass through.
private JButton create;

public void initGUI(){

   frame = new JFrame();
   frame.setSize(325, 350);
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setTitle("Class Design - Fill in Class UML");

   JPanel CreationPanel = new JPanel();
   CreationPanel.setLayout(new BorderLayout());

   inputUML = new JTextArea("Write UML here");
   inputUML.setLineWrap(true);
   inputUML.setWrapStyleWord(true);
   CreationPanel.add(new JScrollPane(inputUML),BorderLayout.CENTER);
   CreationPanel.add(inputUML,BorderLayout.CENTER);

   Create = new JButton("Create Class");
   CreationPanel.add(Create,BorderLayout.SOUTH);
   //Create.addActionListener(this);


   frame.add(CreationPanel);
 }

 public Frame getFrame() {
       return frame;
   }



 }

So what I want to know, simply, is how I can fix that, is there just a line I’m going wrong? or do I have a massive logic problem in what I’m trying to achieve?

Thanks 🙂

  • 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-30T16:51:12+00:00Added an answer on May 30, 2026 at 4:51 pm

    The simple answer to your question is that it’s quite possible you haven’t instantiated inputUML [ostensibly by calling initGUI()] before calling strings() [which is a terrible name for a method].

    But your problems go far deeper than this. This use of inheritance is completely wrong. Favor composition over inheritance. The use of Magic Numbers is not recommended. The variable names are poor (Java is case sensitive, btw. uml is not the same as UML)…do yourself a favor and start browsing Head First Java and Head First Object Oriented Analysis and Design. Also consider Test Driven Development by Example I know you think you don’t have the time, but it’s much harder to unlearn bad habits than take a little extra time at the beginning to build good ones.

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

Sidebar

Related Questions

I am currently doing an online test system, I want allow admin to create
I am currently doing a project, in which I need to stop the user
Currently doing a group project for college in Java. The assignment is to produce
My class is currently doing Binary Trees as part of our data structures unit.
I'm currently doing something like this; import java.util.*; public class TestHashMap { public static
I'm currently doing this in my nginx.conf: allow 1.2.3.4; deny; What I'd really like
I am currently doing a system on Google App Engine and am very new
Currently doing XML serialization however, it is very slow. Looking for a way to
I am currently doing a programming assignment and it says that we should store
I'm currently doing a project in C# working with windows forms. During the course

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.