Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: 65535 bytes java limit

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default 65535 bytes java limit

    Good day everyone!

    First of all, I'm so new in programming, but I'm willing to learn.
    Here's my problem..

    I draw an image, a cartoon characters. I use java language. Yeah, I know how to do that but my problem is I'm not able to finish it because I'm exceeding the 65535 bytes java limit because I have a lot of coordinates.
    This image that I'm drawing and my code is on the attachment (unfinished because of error )

    I already made a class that extends JComponent even though it's not needed just because I want to have a space for my coordinates

    Can you help me solve my problem on where to put the other coordinates?
    Actually that is my main problem, where to put the coordinates


    Thanks in advance
    Attached Images Attached Images
    Attached Files Attached Files


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: 65535 bytes java limit

    If you want help, you'll have to provide an SSCCE that demonstrates exactly what you're doing. Note that this should not be an attachment and should not be your entire program, but should be enough so we can copy and paste it into our own editors and play around with it. You'll also want to copy and paste the exact text of any errors you're getting, as well as point out exactly which line the error occurs on.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    xpoiled7 (August 28th, 2013)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 65535 bytes java limit

    I have a lot of coordinates
    If you have near 60K bytes of data, it should be put into a disk file and read into the program instead of hardcoding it in the program.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    xpoiled7 (August 28th, 2013)

  6. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: 65535 bytes java limit

    @KevinWorkman

    I don't know if I can make this clear but I will try

    I am drawing an image. In order to do that,
    I use
    g.fillPolygon(a, b, a.length)
    so that means I need to declare first an array of coordinates(which is a[] for x coordinates, and b[] for y coordinates) to draw one polygon or shape.

    If you saw the image, that has a lot of shape and I need a lot of coordinates for it(the drawing) to be precise. But I think java has a limit of 65535 bytes per method.

    so I don't know where to put my other array or coordinates.




    @Norm

    How can I do that?
    Did you mean I can declare a variable wriiten in a text file? and read it in a program?


    Sorry, I'm so new to this

    Thanks for helping guys

  7. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: 65535 bytes java limit

    Use multiple polygons rather than one to draw the whole image.

  8. The Following User Says Thank You to GregBrannon For This Useful Post:

    xpoiled7 (August 29th, 2013)

  9. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 65535 bytes java limit

    How can I do that?
    Did you mean I can declare a variable wriiten in a text file? and read it in a program?
    Define the variable in the program. Read its contents from a file. something like this:
    open file
    read size of array into int variable
    define array using that size: int[] anArray = new int[theSizeFromFile];
    begin loop
    read value from file and assign it to next element in array
    end loop
    close file
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    xpoiled7 (August 29th, 2013)

  11. #7
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: 65535 bytes java limit

    @GregBrannon

    That's what I'm doing


    @Norm

    Can you give me a sample code for that please? If that's okay with you



    Thank you so much for the help guys

  12. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 65535 bytes java limit

    I posted pseudo code in post #6. Look at using the Scanner class for methods to read the data from the file.
    If you don't understand my answer, don't ignore it, ask a question.

  13. The Following User Says Thank You to Norm For This Useful Post:

    xpoiled7 (August 30th, 2013)

  14. #9
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: 65535 bytes java limit

    I did what you told me but there's a problem.

    I can only do that on one array(xArray) and not on yArray

    Here's my code
    public void paint(Graphics g){
    	 Scanner sc = null;
    	 int i=0;
    	 try
    	 {
    	 sc = new Scanner(new FileInputStream("C:\\x.txt"));
    	 sc.useDelimiter(",");
    	 }
    	 catch(Exception e)
    	 {
    	 System.out.println("file not found!");
    	 }
    	 int[] xArray = new int[4];
     
    	 while (sc.hasNextInt( )){
    			xArray[i++] = sc.nextInt( );
    			}
    		 sc.close( );
     
    	 int[] yArray = {58,58,122,122};
     
    		g.setColor(Color.BLACK);
    		g.fillPolygon(xArray, yArray, xArray.length);
    }
    I can draw using that code.


    But if I do this
    public void paint(Graphics g){
    	 Scanner sc = null;
    	 Scanner sc1 = null;
    	 int i=0;
    	 try
    	 {
    	 sc = new Scanner(new FileInputStream("C:\\x.txt"));
    	 sc.useDelimiter(",");
    	 sc1 = new Scanner(new FileInputStream("C:\\y.txt"));
    	 sc1.useDelimiter(",");
    	 }
    	 catch(Exception e)
    	 {
    	 System.out.println("file not found!");
    	 }
    	 int[] xArray = new int[4];
     
    	 while (sc.hasNextInt( )){
    			xArray[i++] = sc.nextInt( );
    			}
    		 sc.close( );
     
    	 int[] yArray = new int[4];
     
    	 while (sc1.hasNextInt( )){
    			yArray[i++] = sc1.nextInt( );
    			}
    		 sc1.close( );
     
    		g.setColor(Color.BLACK);
    		g.fillPolygon(xArray, yArray, xArray.length);
    }
    I got runtime error


    Can you tell me how can I add more array using that technique?



    Thanks again.

  15. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 65535 bytes java limit

    I got runtime error
    You should copy the full text of the error message and post it here.

    You should NOT put code that reads a file inside the paint() method. The code to read the file should be executed one time in a method outside of the paint() method so that all the data is ready to use when paint() is called.


    The posted code has the array's size hardcoded in the program as having only 4 elements. If the number of elements can change, the number of elements should be in the file with the rest of the data.
    For example: If there are 5 data points the file could contain: 5 233 456 343 22 54
    Read the 5, create an array for 5 elements and then in a loop read the 5 numbers.
    If you don't understand my answer, don't ignore it, ask a question.

  16. The Following User Says Thank You to Norm For This Useful Post:

    xpoiled7 (August 30th, 2013)

  17. #11
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: 65535 bytes java limit

    Thank you so much for the big help sir

    I already got it. Hopefully I don't get the 65535 byte error thing again because I started all over again. Let's see if it occurs again



    By the way, why did you say this?
    Quote Originally Posted by Norm View Post
    You should NOT put code that reads a file inside the paint() method. The code to read the file should be executed one time in a method outside of the paint() method so that all the data is ready to use when paint() is called.
    Is that important? I mean, my code worked already.

    Can you tell me why?



    Thanks again sir.

  18. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 65535 bytes java limit

    The paint() method draws what is seen in the GUI. It should NOT do anything that takes time and can slow down the drawing of the GUI. The paint() method i called by the JVM when it thinks the GUI needs to be updated. like when another window covers it.

    In general you should only read data from a file one time and save it for later uses. Don't read a file every time you want to use it. Read it once and save it.
    If you don't understand my answer, don't ignore it, ask a question.

  19. The Following User Says Thank You to Norm For This Useful Post:

    xpoiled7 (August 30th, 2013)

  20. #13
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: 65535 bytes java limit

    So where should I put the codes? In the main method?
    If yes, how can I use it in paint method?

    I'm so sorry. I'm so new at this


    Thank you.

  21. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 65535 bytes java limit

    Define the arrays as class variables (outside of any methods). As class variables all methods in the class will be able to access them.
    Define a method that reads the data from the file an saves it in the arrays.
    Call that method from the class's constructor.
    Use the contents of the arrays in the paint() method.
    If you don't understand my answer, don't ignore it, ask a question.

  22. The Following User Says Thank You to Norm For This Useful Post:

    xpoiled7 (August 30th, 2013)

Similar Threads

  1. Java integer limit
    By jobi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 4th, 2013, 03:27 PM
  2. Replies: 0
    Last Post: December 11th, 2012, 05:08 PM
  3. [SOLVED] How to read and shuffle bytes from text file in Java....?'
    By suyog53 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: September 21st, 2012, 10:22 AM
  4. How do i limit the input time
    By itayj in forum Java Theory & Questions
    Replies: 6
    Last Post: October 24th, 2011, 03:47 PM
  5. Java Sockets, Bytes / Objects
    By AdamD in forum Java Networking
    Replies: 1
    Last Post: January 31st, 2011, 03:25 PM