0

So I have an array of Points

Point[] point ={new Point (x,y), ....}

And an array of Lines from those points

Line[] line = {new Line(point[1],point[5]),....}

If I store this in a class i exceed the 65535 bytes.

I thought of getting it from external files as splitting them up in other classes is no option. But the lines have to get their points from the point array.

So if anyone has an idea on how to do this?

partlov
  • 13,789
  • 6
  • 63
  • 82
kristof
  • 1
  • 1
  • Wait, are you defining 65,536 literal `Point` objects in your _class definition_? – Louis Wasserman Jan 23 '13 at 22:07
  • @LouisWasserman It's a good many less points than that, but still a good question - "Why are there *so many* in the class definition?" :P –  Jan 23 '13 at 22:10
  • 1
    @LouisWasserman Methods are limited to 65536 bytes long, even initialisers. It's the byte code generated to build the arrays which takes that long. – Peter Lawrey Jan 23 '13 at 22:10
  • I would revisit the "no option" assumption. –  Jan 23 '13 at 22:13
  • Loading from a resource would be prefered but you could always use multiple initialisation methods, if you want to do it in a class. – BevynQ Jan 23 '13 at 22:30

2 Answers2

2

Read in the points from a text file e.g.

x0 y0
x1 y1
... etc

Read in the lines as a series of point numbers

1 5 etc
0 3 6 9 etc

You can use BufferedReader and split() or careful use of Scanner.

Instead of defining all your Points in advance you could define your lines as a series of points. This would be far easier to maintain.

1,2 3,4 5,6 etc
2,1 4,5 0,7 etc
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

you can use a static initialiser:

static {
   Point[] points;
   int i =0;
   for(int x=0;x<something;x++){
       for(int y=0;y<something;y++){
           point[i] = new Point(x,y);
       }
   }
}

If the points cannot be calculated, because they are values, store them in a file, as peter wrote.

Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79