【问题标题】:trying to create a class objext iside an other class试图在另一个类中创建一个类对象
【发布时间】:2014-11-02 16:51:03
【问题描述】:

我正在尝试将一个类点的对象创建到另一个类 InterestPoint 中,有些话我希望能够在我的 INterestPoint 类中使用 Points 值但不使用遗传

public class InterestPoint {

    private Point p1;
    private String aeria;

    public InterestPoint() {
        this.p1 = new Point();
        //p1.dysplay1();
    }

}

编辑

不,当我调用我的方法通过类函数打印我的观点时,你误解了它会打印一个错误,上面写着:

Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
    at Point.dysplay1(Point.java:29)
    at InterestPoint.setall1(InterestPoint.java:22)
    at Main.main(Main.java:16)
Java Result: 1

这就是我发布这个问题的原因:D

【问题讨论】:

  • 你的问题是?
  • 你卡在哪里了?你怎么卡住了?你可以像你正在做的那样使用组合,并为 p1 提供一个 getter 方法。请注意,我试图修复您的代码格式。将来,您将希望自己为您在此处发布的任何代码执行此操作。

标签: java class object


【解决方案1】:

回复:

Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
    at Point.dysplay1(Point.java:29)
    at InterestPoint.setall1(InterestPoint.java:22)
    at Main.main(Main.java:16)
Java Result: 1

射击,你并没有向我们展示你的整个 InterestPoint 类,尤其是你拥有的方法必须看起来像:

public void setAll1() {
   throw new UnsupportedOperationException("Not supported yet");
}

解决方案是摆脱 throws 调用并放入有意义的代码。

public void setAll1() {
   // get rid of this throw exception call
   // throw new UnsupportedOperationException("Not supported yet");

   // add some sensible code here
}

【讨论】:

    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多