java.io.IOException: OPEN WRITE failed

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

java.io.IOException: OPEN WRITE failed

Postby FIREBALL5 » Sat Dec 24, 2011 8:25 pm

Hello,
Just registered here, need to ask a question.
I have worked with leJOS in high school (using Windows XP 32-bit) and never had any problems.
After spending most of the day yesterday trying to get leJOS set up on my Windows 7 64-bit, I have made some progress - now I am having other problems.
I have posted the code and the error at the bottom of this post.

I am using:
Eclipse SDK / Version: 3.7.1 / Build id: M20110909-1335
And, I have installed the leJOS NXJ plugin for eclipse.
This is a 64 bit machine, but I currently am using Java 32 bit:
Code: Select all
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

I have tried both Bluetooth and USB.

I used the leJOS installer and NXJ_HOME is located in C:\Program Files (x86)\leJOS NXJ.

I have checked several resources, including:
A) the documentation
B) http://nxtemplar.blogspot.com/
C) others...

PLEASE let me know if there is any more information I can give.
The "LEGO MINDSTORMS NXT 2.0" application does upload - but I am much less comfortable here.

I am curious if this is a problem with my brick or with my Eclipse configuration or something with leJOS.

Thanks in advance!

- John

Below is my (very basic) code, and this is configured in Eclipse as a leJOS project.
Code: Select all
package main;

import lejos.nxt.Motor;

public class MoveMotorA {

   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      Motor.A.forward();
   }

}

Code: Select all
Linking ...
Program has been linked successfully
Uploading ...
BlueCove version 2.1.0 on winsock
leJOS NXJ> Connected to NXT
java.io.IOException: OPEN WRITE failed
   at lejos.nxt.remote.NXTCommand.openWrite(NXTCommand.java:179)
   at lejos.nxt.remote.NXTCommand.uploadFile(NXTCommand.java:450)
   at lejos.pc.tools.Upload.upload(Upload.java:51)
   at lejos.pc.tools.NXJUpload.run(NXJUpload.java:93)
   at lejos.pc.tools.NXJUpload.start(NXJUpload.java:36)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at lejos.pc.tools.ToolStarter.startTool(ToolStarter.java:31)
   at lejos.pc.tools.NXJUpload.main(NXJUpload.java:29)
BlueCove stack shutdown completed
uploading the program failed with exit status 1
FIREBALL5
New User
 
Posts: 4
Joined: Sat Dec 24, 2011 7:56 pm
Location: Idaho

Re: java.io.IOException: OPEN WRITE failed

Postby gloomyandy » Sat Dec 24, 2011 10:50 pm

What happens if you compile and run this code from the command line?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3966
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: java.io.IOException: OPEN WRITE failed

Postby skoehler » Sun Dec 25, 2011 1:45 am

"OPEN WRITE failed" is a an exception thrown by some leJOS code, when the NXJ command to open a file fails. There might be several reasons for that.

- Is the filename too long? Try uploading another file with nxjupload.bat
- Is the NXT out of space to store files?

Which firmware are you running on the brick?
In fact, communication with the bricks seems to be working, however, the NXT returns an error.
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm

Re: java.io.IOException: OPEN WRITE failed

Postby FIREBALL5 » Sun Dec 25, 2011 5:20 am

gloomyandy wrote:What happens if you compile and run this code from the command line?


I followed the instructions on page 7 of the following PDF: http://www.variantpress.com/file_download/5
After I enter "nxjc MoveMotorA.java" below, a file "MoveMotorA.class" is generated in this path; shouldn't it be a ".nxd" or ".nxj" file?

Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\John>cd C:\Users\John\workspace\lejosProject\src\main

C:\Users\John\workspace\lejosProject\src\main>nxjc MoveMotorA.java
C:\Users\John\workspace\lejosProject\src\main>nxj -r MoveMotorA
leJOS NXJ> Linking...
js.tinyvm.TinyVMException: found class main.MoveMotorA instead of requested MoveMotorA
        at js.tinyvm.ClassRecord.getClassRecord(ClassRecord.java:876)
        at js.tinyvm.Binary.processClasses(Binary.java:365)
        at js.tinyvm.Binary.createFromClosureOf(Binary.java:312)
        at js.tinyvm.TinyVMTool.link(TinyVMTool.java:98)
        at js.tinyvm.TinyVMTool.link(TinyVMTool.java:49)
        at lejos.pc.tools.NXJLink.start(NXJLink.java:134)
        at lejos.pc.tools.NXJLinkAndUpload.run(NXJLinkAndUpload.java:108)
        at lejos.pc.tools.NXJLinkAndUpload.start(NXJLinkAndUpload.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at lejos.pc.tools.ToolStarter.startTool(ToolStarter.java:31)
        at lejos.pc.tools.NXJLinkAndUpload.main(NXJLinkAndUpload.java:42)
C:\Users\John\workspace\lejosProject\src\main>


In reply to skoehler:

How can the filename be too long? "MoveMotorA" is 10 characters! And why can't I get a more descriptive error if this is the case?
How can I find out how much space is available? There's only one program on it (done with the Lego software), it shouldn't be full?

The brick's firmware version is 1.31.
I am wondering what is wrong with my brick; when Eclipse (with Run after upload enabled) does upload a file (which seems to only work on new files that don't exist on the brick already), or when I do it through command line (even specifying the -r flag), the application does not run (and pressing the orange button doesn't start it), and I cannot find it anywhere, in the Software files folder or the NXT files folder, anywhere.

If there's anymore information you need, please let me know.
And thanks again for your continued assistance.

Merry Christmas to those of you that celebrate it!
FIREBALL5
New User
 
Posts: 4
Joined: Sat Dec 24, 2011 7:56 pm
Location: Idaho

Re: java.io.IOException: OPEN WRITE failed

Postby gloomyandy » Sun Dec 25, 2011 8:33 am

If you want to run your program on the nxt you need to install the leJOS firmware on it not the Lego firmware. Also to use the command line to create an .nxj file you need to run the linker command nxjlink. I would recommend following the official leJOS tutorial rather than other web sites. Other sites are often out of date...

Andy

PS happy Xmas!
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3966
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: java.io.IOException: OPEN WRITE failed

Postby skoehler » Sun Dec 25, 2011 11:37 am

FIREBALL5 wrote:In reply to skoehler:

How can the filename be too long? "MoveMotorA" is 10 characters! And why can't I get a more descriptive error if this is the case?


MoveMotorA is not too long.

FIREBALL5 wrote:How can I find out how much space is available? There's only one program on it (done with the Lego software), it shouldn't be full?


No clue how you can determine the free space with the lego firmware. Probably, the Lego firmware reject the file extension (*.nxj). It's a theory.

FIREBALL5 wrote:The brick's firmware version is 1.31.


leJOS is not like robotc or nxc. You need to flash the leJOS firmware in order to be able to run Java programs. Execute nxjflash on the command line.
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm

Re: java.io.IOException: OPEN WRITE failed

Postby skoehler » Sun Dec 25, 2011 11:54 am

FIREBALL5 wrote:
Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\John>cd C:\Users\John\workspace\lejosProject\src\main

C:\Users\John\workspace\lejosProject\src\main>nxjc MoveMotorA.java
C:\Users\John\workspace\lejosProject\src\main>nxj -r MoveMotorA
leJOS NXJ> Linking...
js.tinyvm.TinyVMException: found class main.MoveMotorA instead of requested MoveMotorA
        at js.tinyvm.ClassRecord.getClassRecord(ClassRecord.java:876)
        at js.tinyvm.Binary.processClasses(Binary.java:365)
        at js.tinyvm.Binary.createFromClosureOf(Binary.java:312)
        at js.tinyvm.TinyVMTool.link(TinyVMTool.java:98)
        at js.tinyvm.TinyVMTool.link(TinyVMTool.java:49)
        at lejos.pc.tools.NXJLink.start(NXJLink.java:134)
        at lejos.pc.tools.NXJLinkAndUpload.run(NXJLinkAndUpload.java:108)
        at lejos.pc.tools.NXJLinkAndUpload.start(NXJLinkAndUpload.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at lejos.pc.tools.ToolStarter.startTool(ToolStarter.java:31)
        at lejos.pc.tools.NXJLinkAndUpload.main(NXJLinkAndUpload.java:42)
C:\Users\John\workspace\lejosProject\src\main>



Never compile/link from inside a package folder. The command should have been
Code: Select all
cd C:\Users\John\workspace\lejosProject\src
nxjc main\MoveMotorA.java
nxj -r main.MoveMotorA


In fact, since you are using Eclipse, the above is discouraged, since it places a *.class in the java sources folder. To use the *.class files generated by Eclipse, which are kept inside the bin subfolder, the following would have sufficed:
Code: Select all
cd C:\Users\John\workspace\lejosProject
nxj -cp bin -r main.MoveMotorA
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm

Re: java.io.IOException: OPEN WRITE failed

Postby FIREBALL5 » Mon Dec 26, 2011 5:02 am

I wasn't aware that the Lego and leJOS firmwares were different... it is safe to say that the Lego application no longer work?
I have now installed the leJOS firmware - leJOS 0.9.0 is what I see when the brick powers up.

For now, I no longer seem to have any problems uploading my applications, but as soon as I try to run them through Eclipse, they do not run and the brick restarts. Same thing happens when I issue the equivalent commands through the command line. Note that I am not using the nxjlink and nxjupload commands whatsoever, the documentation states that the nxj command does this automatically.

Please let me know if there is any more information I can provide.
If it helps, leJOS reports my battery level at 7.5. Using non-rechargeable Alcaline batteries.
Once again, I am running on Windows 7, 64x machine running 32x Java and 32x Eclipse.

Thanks!
FIREBALL5
New User
 
Posts: 4
Joined: Sat Dec 24, 2011 7:56 pm
Location: Idaho

Re: java.io.IOException: OPEN WRITE failed

Postby skoehler » Mon Dec 26, 2011 11:12 am

Your program is running. But it terminates immediately. Add Button.waitForPress(); to the end of the main method.
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm

Re: java.io.IOException: OPEN WRITE failed

Postby FIREBALL5 » Mon Dec 26, 2011 5:05 pm

Thanks everyone for their assistance - all problems are now resolved. I can upload and run my leJOS applications with no problems.
FIREBALL5
New User
 
Posts: 4
Joined: Sat Dec 24, 2011 7:56 pm
Location: Idaho


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff