Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello, I am trying to define a byt

Status
Not open for further replies.

25884

Programmer
Mar 12, 2001
46
AP
Hello,
I am trying to define a byte array in a method.My problem is that the byte array is very large and i get the following exception at run time, the code compiles easily.
-------------------------------------------
Exception in thread "main" java.lang.ClassFormatError: CreateSoundBuffer (Code o
f a method longer than 65535 bytes)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:11
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
Press any key to continue . . .
------------------

One solution i figured was to break the array into two,in which case the size is accomodated.But i want to define the whole array in one go..is there a way i can specify "no size limit" for the method? Can any different Class Loader be defined which can override the length constraints?
I would like a reply soon please.
Thanks in advance,
Sonali.
 
Hi Sonali,
could you please add that portion of your source code?

To me it seems as if you're using a static array (something like byte b[200000] for example) but you should dynamically allocate it, like byte b[]=new byte [200000].

I tested it with the following code, and it works fine:
Code:
public class c
{
   byte b[]=new byte[20000000];
   public static void main(String args[])
   {
      c cc=new c();
      System.out.println("hello");
   }
}
[\code]

Christoph
 
Would using a java.io.ByteArrayOutputStream help instead?
 
I don't know, what exactly you're trying to do, but as it seems, you wanna setup some sound buffer, i guess write some bytes in it and from time to time read it completely!?

Then ByteArrayOutputStream would be fine.

If you know, how many bytes you will write to the buffer and the size stays the same, then i would recommend rather using a byte[] as shown in the example code due to speed optimization

Christoph
 
Another idea: Create a custom class that contains a Vector and a accessor method byte getByte(BigInteger index);
Each time the byte array gets very large, just add it to the vector and make a new one. Then you can use modular arithmetic to calculate the index of the byte you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top