Processing not compiling my code anymore

Hi guys. I am having a problem. I was running a sketch on processing on my old PC with windows 7 and it worked fine. the IDE compiled it and the compiled .exe file also worked. that computer’s hard drive stopped working but I had it all saved, of course.

But now I am trying to open the same files on another computer, also with windows 7 and neither the sketch or the compiled files work :o
Any idea what could be happening here? Here is the error the IDE shows when trying to run the sketch from it.
Thank You.

ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
Could not run the sketch (Target VM failed to initialize).

Also, the following line is highlighted in the IDE.

portName = Serial.list()[0]; //0 as default

Funny, if I connect a Serial device to the PC, the sketch runs. It looks like there might be a problem loading COM1 (Default)?
COM 1 also does not appear on the COM Port list… Any ideas why this is happening?

COM 1 doesn’t seem to show up on other programs, Arduino for example. I am at loss with this, but at least I found a way of running the sketch.

I deleted the COM port checking when adding the drop down list, now it opens even if a COM port is not selected, but it still does not export the app for windows.

Hi @jhsa,

It seems that you are trying to access a part of the array that does not exist. If you don’t have any device connected to the serial port then the Serial.list()[0] is empty and an exception is thrown.

You can try to wrap the Serial.list() port assignment into a try-catch block to catch the exception and act accordingly.

try{
    port = Serial.list()[0];
} catch(ArrayIndexOutOfBoundsException e){
   println("Could not assign port");
   exit; //close the sketch
}

Hope it helps!

I guessed that was the case… I removed the port check from setup. the code now works even without a serial device connected, but I still don’t get it to compile… It compiled fine on my other PC. I do not understand this :frowning: Perhaps some bug on thkis version of the IDE?

It is better to have a check to ensure that the port can be assigned. Otherwise, we will try to always access to memory that is not assigned (garbage values)

When there isn’t any port connected, it doesn’t even open the drop down list… I think this is fine? My problem now is that it is not compiling for windows. It seems to compile for Linux.
Here is the error:

BUILD FAILED
D:\Backups\Music PC\Electronic Projects\Arduino Experiments\Arduino and Processing experiments\Serial communication\Processing\Eeprom Editor\New_Add Real Time Editing\iL8EepromEditor_181_FixCrashOnStart_COMPort\windows-amd64\launch4j-build.xml:5: net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: Exec failed (1): D:\Programs\processing-4.0b8\modes\java\application\launch4j\bin\ld.exe -mi386pe --oformat pei-i386 --dynamicbase --nxcompat --no-seh --subsystem windows -s D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\crt2.o D:\Programs\processing-4.0b8\modes\java\application\launch4j\head\guihead.o D:\Programs\processing-4.0b8\modes\java\application\launch4j\head\head.o C:\Users\Joao\AppData\Local\Temp\launch4j7689369404656130397o D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmingw32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmingwex.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libgcc.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmsvcrt.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmoldname.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libkernel32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libuser32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libadvapi32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libshell32.a -o D:\Backups\Music PC\Electronic Projects\Arduino Experiments\Arduino and Processing experiments\Serial communication\Processing\Eeprom Editor\New_Add Real Time Editing\iL8EepromEditor_181_FixCrashOnStart_COMPort\windows-amd64\iL8EepromEditor_181_FixCrashOnStart_COMPort.exe
	at net.sf.launch4j.Builder.build(Builder.java:149)
	at net.sf.launch4j.ant.Launch4jTask.execute(Launch4jTask.java:111)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
	at org.apache.tools.ant.Task.perform(Task.java:350)
	at org.apache.tools.ant.Target.execute(Target.java:449)
	at org.apache.tools.ant.Target.performTasks(Target.java:470)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
	at processing.mode.java.JavaBuild.buildWindowsLauncher(JavaBuild.java:1137)
	at processing.mode.java.JavaBuild.exportApplication(JavaBuild.java:980)
	at processing.mode.java.JavaBuild.exportApplication(JavaBuild.java:591)
	at processing.mode.java.JavaMode.handleExportApplication(JavaMode.java:183)
	at processing.mode.java.ExportPrompt.trigger(ExportPrompt.java:495)
	at processing.mode.java.ExportPrompt.trigger(ExportPrompt.java:157)
	at processing.mode.java.JavaEditor.handleExportApplication(JavaEditor.java:516)
	at processing.mode.java.JavaEditor.lambda$buildFileMenu$0(JavaEditor.java:239)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:374)
	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1028)
	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1072)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6626)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389)
	at java.desktop/java.awt.Component.processEvent(Component.java:6391)
	at java.desktop/java.awt.Container.processEvent(Container.java:2266)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: net.sf.launch4j.ExecException: Exec failed (1): D:\Programs\processing-4.0b8\modes\java\application\launch4j\bin\ld.exe -mi386pe --oformat pei-i386 --dynamicbase --nxcompat --no-seh --subsystem windows -s D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\crt2.o D:\Programs\processing-4.0b8\modes\java\application\launch4j\head\guihead.o D:\Programs\processing-4.0b8\modes\java\application\launch4j\head\head.o C:\Users\Joao\AppData\Local\Temp\launch4j7689369404656130397o D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmingw32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmingwex.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libgcc.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmsvcrt.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libmoldname.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libkernel32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libuser32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libadvapi32.a D:\Programs\processing-4.0b8\modes\java\application\launch4j\w32api\libshell32.a -o D:\Backups\Music PC\Electronic Projects\Arduino Experiments\Arduino and Processing experiments\Serial communication\Processing\Eeprom Editor\New_Add Real Time Editing\iL8EepromEditor_181_FixCrashOnStart_COMPort\windows-amd64\iL8EepromEditor_181_FixCrashOnStart_COMPort.exe
	at net.sf.launch4j.Util.exec(Util.java:156)
	at net.sf.launch4j.Cmd.exec(Builder.java:215)
	at net.sf.launch4j.Builder.build(Builder.java:117)
	... 57 more

Total time: 0 seconds


I don’t understand. Are you trying to use processing for Linux or Windows?

Processing for windows and on windows 7, 64 bit.
It doesn’t build the app for windows, so I tried to build for Linux and it does without errors. I am guessing that there is some java problem here?

Are you sure you installed Processing for Windows and not Linux on your machine? (just trying to guess before digging into deeper)

I believe the Linux version wouldn’t even run on windows.

And I am seeing another error that makes no sense at all, even because the program runs from the IDE itself. If I click on “Errors” it shows:

TAB 0,LN 5816LN START OFF: 178738,LN STOP OFF: 178739,PROB: Missing right curly bracket “}” Missing right curly bracket “}” iL8EepromEditor_181_FixCrashOnStart_COMPort 5817

But it it is actually not missing anything. The function has all the brackets.

Have you tried reinstalling it?
Maybe something went wrong…I can’t seem to find anything when searching the posted error
Maybe the file is corrupted since you said the hard driver stopped. You can also check for the java version and try to update it…

Can you post your code for others to try and maybe reproduce the problem?

I will try to reinstall processing. But I just have to unzip it to some disk, right? I placed it on disk D/Program Files.
I will zip the code and post it… Can I post zip files here?

I don’t understand. This code compiled and built the apps fine on my other PC with the same windows 7. On this PC it doesn’t want to work, WHY??

Ok, I think I might have found a couple bugs on the latest version of the Processing IDE software.
1 - A right curly bracket error that does not exist. Former Processing version does not show this error when running the same code.
2 - It wasn’t building a windows file, probably because of a too long file name. After making it shorter, it built the windows application.
3 - The compiled exe file does not open at all, and I have noticed that it is a bit smaller than it should, About 69k when it should be around 87k.
Tried to build an example sketch after saving it on my PC. It gives an exe file but it also doesn’t open.
Compiled my code on former version 3 and the IDE built the windows application, and it does open, and it works…

The version I had on my computer that got broken was some version of Procession 4 that actually worked on that computer. Version 4 doesn’t seem to want to work correctly on this PC.

This will probably be a stupid question, but did your older computer run a x64 windows too?
Also, do you have many installations of java?
I use to have an openjava I use with android, a java 8 included with processing 2 and a java 8 included with the app I use for logging into government sites. I have to change my java path often!

Both computers on win 7, 64 bit. Only one installation of java as far as I know. The other computer that had the hard drive dying was an AMD. This one has an i5 processor. that is the major difference between them. Not sure it makes any difference as far as this problem is concerned though

For testing things quickly you might want two or more versions of Processing ‘installed’ (simply copying the Processing folder is enough). I have C:\Programs\Processing (that’s v4) and C:\Programs\processing-3.3.6. After using one, make sure all Processing windows are closed, then run the other.

Try to set com1 inside sketch not as default

void setup()
{
  
  String portName = "COM1";// Change the number (in this case ) to match the corresponding port number connected to your Arduino. 

  myPort = new Serial(this, portName, 9600);
}

Summarize your issue because it multiplied after your subsequent comments

Thanks jafal.
I kinda fixed it by commenting the line in setup when I added the dropdown list.

portName = Serial.list()[0]; //0 as default

I replaced it with portName = “NONE”. Now the app doesn’t crash if there isn’t a serial device connected to the computer. Still can’t understand the missing “}” problem when there isn’t any missing. On an older processing version, this error does not come up…