【问题标题】:Array of Polygons多边形数组
【发布时间】:2017-01-21 09:25:13
【问题描述】:

我想定义多边形数组,所以:

private static ArrayList<PolyDefault> basePolyList = new ArrayList<PolyDefault>();
//read the file and store to basePolyList
parser.readBaseFile(filename_1, basePolyList);
//get size of basePolyList
int SizeOfBase = basePolyList.size();
//def Array of polygon      
Poly[] p4=new PolyDefault[SizeOfBase];
for(int i=0;i<SizeOfBase;i++)
{
  p4[0].add(basePolyList.get(i));
  System.out.println("Poly of Base["+i+"]"+" has " +p4[i].getNumPoints()+"\n");
}

但我有这个错误: 线程“main”中的异常 java.lang.NullPointerException ... 感谢任何帮助...

【问题讨论】:

    标签: java arrays pointers polygon intersect


    【解决方案1】:

    你必须初始化数组的对象:

    for(int i=0;i<SizeOfBase;i++)
    {
        p4[i] = new Poly();
        p4[i].add(basePolyList.get(i));
        System.out.println("Poly of Base["+i+"]"+" has " +p4[i].getNumPoints()+"\n");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 1970-01-01
      • 2018-06-11
      • 2013-10-08
      • 2013-03-20
      • 2011-08-01
      • 1970-01-01
      相关资源
      最近更新 更多