FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Assigning objects with a String name ????
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Assigning objects with a String name ????  (Read 448 times)
mKoser

WWW Email
Assigning objects with a String name ????
« on: Jul 28th, 2003, 6:08pm »

Hi,
 
I want to assign a name for each object created, it needs to be a string because it will contain personal data and therefore each object will be called the persons name.
 
But, I get a whole lot of errors when trying to run this bit of code:
 
Code:

// converting integer to string
// mikkel crone koser
 
obj[] objArray = new obj[5];
 
void setup(){
  for(int i = 0; i < objArray.length; i++){
    String tmpName = "objNum_" + Integer.toString(i);
    objArray[i] = new obj(tmpName);
  }
}
 
class obj{  
  obj(String str){
    println(str + " was created!");
  }
}

 
This is the error messages I get when I run it (sorry for the mess!):
------------------------------------------------------------------------ -----------------------
java.lang.VerifyError: (class: Temporary_1195_4933$obj, method: <init> signature: (LTemporary_1195_4933;Ljava/lang/String;)V) Incompatible object argument for function call
      at Temporary_1195_4933.setup(Temporary_1195_4933.java:14)
      at BApplet.init(BApplet.java:97)
      at KjcEngine.start(KjcEngine.java:752)
      at PdeEditor.doRun(PdeEditor.java:697)
      at PdeBase.actionPerformed(PdeBase.java:934)
      at java.awt.MenuItem.processActionEvent(MenuItem.java:58
      at java.awt.MenuItem.processEvent(MenuItem.java:54
      at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:285)
      at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
      at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:28
      at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:452)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThrea d.java:197)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread. java:150)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
------------------------------------------------------------------------ -----------------------
 
any help is greatly apriciated
 
Cheers,
Mikkel
« Last Edit: Jul 28th, 2003, 11:20pm by mKoser »  

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
toxi

WWW
Re: Assigning objects with a String name ????
« Reply #1 on: Jul 28th, 2003, 11:02pm »

mikkel, this is the nasty parser bug again which is caused by using processing style syntax in a class constructor. AFAIK this should be fixed in the next revision. for now the only work around is using the standard java style syntax for println():
 
System.out.println("blah");
 
..or have the constructor call its own init method. e.g.
 
Code:
class obj {
  obj(String str) {
    this.init(str);
  }
  void init(String str) {
    println(str + " was created!");
  }
}

 
do a search on the boards for "constructor" it should come up with quite a few posts about similar problems.
 
hth, toxi.
 

http://toxi.co.uk/
mKoser

WWW Email
Re: Assigning objects with a String name ????
« Reply #2 on: Jul 28th, 2003, 11:22pm »

Thanks Toxi, it works like a charm
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
Pages: 1 

« Previous topic | Next topic »