不规则多边形程序 [英] Irregular Polygon Program

查看:62
本文介绍了不规则多边形程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我需要帮助的作业:

1.实现一个包含Point2D.Double对象数组列表的IrregularPolygon类。


2. Point2D.Double类定义以double精度指定的点,表示(x,y)坐标空间中的位置。例如,Point2D.Double(2.5,3.1)构造并初始化坐标(2.5,3.1)处的点。


3.使用以下声明作为实验室工作的起点。

展开 | 选择 | Wrap | 行号

解决方案

@ slapsh0t11


It会更直接地说:

展开 | 选择 | Wrap | 行号

程序确实编译了,但是我的代码中以及非测试文件中的toAdd方法中显示的行似乎正在发生。



以下是我一直收到的错误消息:


输入X坐标:3

输入Y坐标:4

线程main中的异常java.lang.NullPointerException

at IrregularPolygon.toAdd(IrregularPolygon.java:28)

at IrregularPolygonTester.main(IrregularPolygonTester .java:19)


OK。


所以你有一个NullPointerException:这意味着当它不应该是某个东西时是空的。如果你取消引用一个null的变量(例如,尝试并调用一个null的方法),或者如果一个数组变量为null并且你试图访问它的一个元素,你就得到这些。


此异常发生在IrregularPolygon.java的第28行

展开 | 选择 | Wrap | 行号


Here is my assignment that I need help with:
1. Implement a class IrregularPolygon that contains an array list of Point2D.Double objects.

2. The Point2D.Double class defines a point specified in double precision representing a location in (x, y) coordinate space. For example, Point2D.Double(2.5, 3.1) constructs and initializes a point at coordinates (2.5, 3.1).

3. Use the following declarations as a starting point for your lab work.

Expand|Select|Wrap|Line Numbers

解决方案

@slapsh0t11
It would be more straight forward to say:

Expand|Select|Wrap|Line Numbers


The program does compile, but something seems to be going on with the line I indicated in my code as well as in the toAdd method in the non-tester file.


Here is the error message I keep receiving:

Enter X-Coordinate: 3
Enter Y-Coordinate: 4
Exception in thread "main" java.lang.NullPointerException
at IrregularPolygon.toAdd(IrregularPolygon.java:28)
at IrregularPolygonTester.main(IrregularPolygonTester .java:19)


OK.

So you have a "NullPointerException": that means that something is null when it shouldn''t be. You get these if you dereference a variable which is null (eg try and invoke a method on something that is null), or if an array variable is null and you try and access one of its elements.

This exception occurs at line 28 of IrregularPolygon.java

Expand|Select|Wrap|Line Numbers


这篇关于不规则多边形程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆