Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

allocate array during run-time

Thread view: 
Wizumwalt@gmail.com - 26 Apr 2006 20:21 GMT
I'm trying to allocate an IntBuffer during run-time once I know the
size I need but I can't get the following to compile. Eclipse
highlights the reason as such ...

[code]
Syntax error on token "]", VariableDeclaratorId expected after this
token.
[/code]

[code]
    private IntBuffer[] indBuffers;

    public void myMethod(int val) {
        indBuffers[] = BufferUtils.newIntBuffer[val];
               // error in above line
               ...
[/code]
Mark Thomas - 26 Apr 2006 20:24 GMT
> I'm trying to allocate an IntBuffer during run-time once I know the
> size I need but I can't get the following to compile. Eclipse
[quoted text clipped - 10 lines]
>     public void myMethod(int val) {
>         indBuffers[] = BufferUtils.newIntBuffer[val];
Leave out the [] - the name of the variable is just indBuffers.
>                 // error in above line
>                 ...
> [/code]

Mark
Oliver Wong - 26 Apr 2006 21:28 GMT
> I'm trying to allocate an IntBuffer during run-time once I know the
> size I need but I can't get the following to compile. Eclipse
[quoted text clipped - 13 lines]
>                ...
> [/code]

Assuming BufferUtils.newIntBuffer is an IntBuffer[][], then you would write
something like:

<code>
indBuffers = BufferUtils.newIntBuffer[val];
</code>

but if BufferUtils.newIntBuffer is actually a method which takes a single
integer as an argument and returns IntBuffer[], then you would write
something like:

<code>
indBuffers = BufferUtils.newIntBuffer(val);
</code>

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.