不规则多边形程序

编程入门 行业动态 更新时间:2024-10-26 02:35:06
本文介绍了不规则多边形程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是我需要帮助的作业: 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

更多推荐

不规则多边形程序

本文发布于:2023-07-27 16:07:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1223307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多边形   不规则   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!