FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 187 : Some simple code doesn't work
Last modified: 2005-10-25 06:25
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
INVALID -
Pr
i
ority:
P2
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
adepali
Assigned To:
fry
Attachment
Type
Created
Size
Actions
Description
: Opened: 2005-10-25 05:06
This code won't compile:
int[] num = new int[ 5 ];
num[ 0 ] = 3;
void hello( )
{
println("HI");
}
I get an unexpected token: void. It always happens when i use any kind of
dynamic allocation. Changing the order like this:
void hello( )
{
println("HI");
}
int[] num = new int[ 5 ];
num[ 0 ] = 3;
I get an "Expecting RBRACK, found '0'" error. The allocation works fine if
specified inside a function block, but not in the global environment.
Additional Comment
#1 From fry 2005-10-25 06:25
that's just a bug in your code. except for in special cases, you cannot
assign the contents of arrays outside of methods.
int[] num = new int[ 5 ];
num[ 0 ] = 3; // this line is just bad syntax
void hello( )
{
println("HI");
}
to fix this, use:
int[] num = new int[ 5 ];
void hello( )
{
num[ 0 ] = 3; // it's ok to do this here
println("HI");
}