 |
 |
Cocoa Java, Arrays
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status:
Offline
|
|
Hello,
I am trying to make some simple applications i XCode using Java, but I can't for the life of me get even the simplest things to work. Example:
int[] foo = new int[3];
foo[0] = 7;
gives me three errors:
']' expected
<identifier> expected
cannot resolve symbol symbol : class foo
Am I missing something really obvious?
Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
In java, every file contains a class. The most basic class that does what you want would look something like this (the filename is Utility.java):
Code:
[arkham@flybook ~] cat Utility.java
public class Utility
{
public static void main(String[] args)
{
int[] foo = new int[3];
foo[0] = 7;
}
}
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status:
Offline
|
|
Originally posted by Arkham_c:
In java, every file contains a class. The most basic class that does what you want would look something like this (the filename is Utility.java):
Code:
[arkham@flybook ~] cat Utility.java
public class Utility
{
public static void main(String[] args)
{
int[] foo = new int[3];
foo[0] = 7;
}
}
Thanks, but I know. The code I posted was just a snip from a class (a data source for an NSTableView). I'm sorry I was being a bit unclear. My class compiles fine with deklarations and creation of objects, however when I try to create an array, I get the errors posted above.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2002
Location: NYC
Status:
Offline
|
|
new is your problem. ints are primitive types and are therefore statically allocated.
the lines should read:
int[3] foo;
foo[0] = 7;
However you will have problems regardless because an NSTableView requires Objects to be viewed inside of it, I am assuimg of the type NSNumber. Maybe Integers would also work but I'm not sure since I don't touch Cocoa Java.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status:
Offline
|
|
Just wondering, but why Cocoa Java? I haven't found a reason to use Java when Cocoa programming at all.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by hayesk:
Just wondering, but why Cocoa Java? I haven't found a reason to use Java when Cocoa programming at all.
Maybe to use some of the good features of java, like all the JDBC drivers or the discovery protocols like JXTA.
Java has a lot to offer in terms of libraries.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status:
Offline
|
|
Originally posted by hayesk:
Just wondering, but why Cocoa Java? I haven't found a reason to use Java when Cocoa programming at all.
Well, why not? I really like Java. The community i very large, and examples tutorials etc. are much easier to find than for Objective-C.
However, I see your point, the best thing would be to use Obj-C, but then, I will have to learn it first. I find the syntax very confusing. 
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status:
Offline
|
|
Originally posted by Arkham_c:
Maybe to use some of the good features of java, like all the JDBC drivers or the discovery protocols like JXTA.
Java has a lot to offer in terms of libraries.
Yes, it does offer a lot of libraries. These can be called from Objective-C.
But don't all Java cocoa calls get translated to objective C, anyway? Wouldn't your code be faster if you only called the Java libraries and used Objective-C in your own code?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|