Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa Java, Arrays

Cocoa Java, Arrays
Thread Tools
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status: Offline
Reply With Quote
Dec 10, 2003, 03:13 PM
 
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
Reply With Quote
Dec 10, 2003, 08:26 PM
 
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
     
beni  (op)
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status: Offline
Reply With Quote
Dec 10, 2003, 09:03 PM
 
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.
     
K++
Senior User
Join Date: Jan 2002
Location: NYC
Status: Offline
Reply With Quote
Dec 10, 2003, 11:34 PM
 
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
Reply With Quote
Dec 12, 2003, 11:54 AM
 
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
Reply With Quote
Dec 12, 2003, 12:20 PM
 
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
     
beni  (op)
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status: Offline
Reply With Quote
Dec 12, 2003, 04:13 PM
 
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
Reply With Quote
Dec 12, 2003, 05:49 PM
 
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?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:32 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2