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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:39:32+00:00 2026-06-08T07:39:32+00:00

I’m getting an error that says java.lang.NullPointerException: null from a code whenever I run

  • 0

I’m getting an error that says java.lang.NullPointerException: null
from a code whenever I run it.

Here is the code:

public class APRectangle
{
    private APPoint myTopLeft;
    private APPoint myTopRight;
    private APPoint myBottomLeft;
    private APPoint myBottomRight;
    private double  myWidth;
    private double  myHeight;

    public APRectangle( APPoint topLeft, double width, double height )
    {
        myTopLeft = topLeft;
        myWidth = width;
        myHeight = height;
    }

    public APPoint getTopLeft()
    {
        return myTopLeft;
    }

    public void setTopLeft( APPoint TL )
    {
        myTopLeft = TL;
    }

    public double getWidth()
    {
        return myWidth;
    }

    public void setWidth( double W )
    {
        myWidth = W;
    }

    public double getHeight()
    {
        return myHeight;
    }

    public void setHeight( double H )
    {
        myHeight = H;
    }

    public APPoint getTopRight()
    {
        return new APPoint( myTopLeft.getX() + myWidth, myTopLeft.getY() );
    }

    public APPoint getBottomLeft()
    {
        return new APPoint( myTopLeft.getX(), myTopLeft.getY() - myHeight );
    }

    public APPoint getBottomRight()
    {
        return new APPoint( myTopRight.getX(), myTopRight.getY() - myHeight );
    }
}

The very last method is the one that is giving me the error.

Here is my main class:

public class MainClass
{
 public MainClass()
 {
    }

 public static String printAPPoint( APPoint p )
 {
     return "(" + p.getX() + "," + p.getY() + ")";
    }

 public static String printAPRectangle( APRectangle R)
 {
     return "[APRectangle " + printAPPoint(R.getTopLeft()) +
            " " + R.getWidth() + "," + R.getHeight() + "]" ;
 }

  public static String printTopLeft( APRectangle R )
 {
     return "(Top Left is " + printAPPoint(R.getTopLeft()) + ")" ;
    }

 public static String printTopRight( APRectangle R )
 {
     return "(Top Right is " + printAPPoint(R.getTopRight()) + ")" ;
    }

public static String printBottomLeft( APRectangle R )
{
    return "(Bottom Left is " + printAPPoint(R.getBottomLeft()) + ")";
}

public static String printBottomRight( APRectangle R )
{
    return "(Bottom Right is " + printAPPoint(R.getBottomRight()) + ")";
}

 public static void main(String[] args)
 {
     APPoint p = new APPoint(1.0, 5.0 );
     APRectangle R = new APRectangle( p, 5.0, 3.0);
     System.out.println(printAPRectangle(R));
     System.out.println(printTopLeft(R));
     System.out.println(printTopRight(R));
     System.out.println(printBottomLeft(R));
     System.out.println(printBottomRight(R));
     System.out.println( "Done!" );
  }

}

The three methods before the last one work perfectly well, but I don’t know why the last one isn’t working. Can someone help me please?

Thanks, Rohan

  • 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-08T07:39:34+00:00Added an answer on June 8, 2026 at 7:39 am

    You forgot to initialize myTopRight, myBottomLeft, and myBottomRight. The other methods work fine because you don’t use their actual points (but you probably should). AP Computer Science?

    By the way, your exception message is saying this:
    We have a problem because one of our objects doesn’t exist.
    We found the problem when we tried APRectangle.getBottomRight (line 59).
    We were doing APRectangle.getBottomRight because MainClass.printBottomRight (line 35) told us to.
    We were doing MainClass.printBottomRight because MainClass.main (line 46) told us to.
    Hope this clears things up.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.