Hello.
This java app I'm developing on NetBeans 7.
When i run the project, line 4 below:

FileReader input = new FileReader("projects");

is not executed and apparently stops execution.

Only when debuggin the file or running step by step are the next lines executed.
No execution past line 4, except when debugging.

I've tried with and without the file present, but only when debugging is the line executed, otherwise it just stops.

On the IDE, I've enabled web-star (will deploy that way) and used no codebase for local testing.

Any help greatly appreciated.

private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            JOptionPane.showMessageDialog(null, "Will read file", "clear.", WIDTH);
            FileReader input = new FileReader("projects");
            JOptionPane.showMessageDialog(null, "Done reading file", "clear.", WIDTH);            
        } catch (ArrayIndexOutOfBoundsException e) {
            /* If no file was passed on the command line, this expception is
            generated. A message indicating how to the class should be
            called is displayed */
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", WIDTH);

        } catch (IOException e) {
            // If another exception is generated, print a stack trace
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);
            // e.printStackTrace();
        }


    }

is not executed and apparently stops execution.

// e.printStackTrace();

Remove the // so you can see the error message printed.

Thank you NormR1.

Actually the "Unable to open Project file. (IO)" exception does display, but only when debugging. Is all good when debugging, but when run regularly (Run Project F6), the line just before ('will read file' message does show, but next line

FileReader input = new FileReader("projects");


just won't run.

Thank you so much !

Carlos


Hello.
This java app I'm developing on NetBeans 7.
When i run the project, line 4 below:

FileReader input = new FileReader("projects");

is not executed and apparently stops execution.

Only when debuggin the file or running step by step are the next lines executed.
No execution past line 4, except when debugging.

I've tried with and without the file present, but only when debugging is the line executed, otherwise it just stops.

On the IDE, I've enabled web-star (will deploy that way) and used no codebase for local testing.

Any help greatly appreciated.

private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            JOptionPane.showMessageDialog(null, "Will read file", "clear.", WIDTH);
            FileReader input = new FileReader("projects");
            JOptionPane.showMessageDialog(null, "Done reading file", "clear.", WIDTH);            
        } catch (ArrayIndexOutOfBoundsException e) {
            /* If no file was passed on the command line, this expception is
            generated. A message indicating how to the class should be
            called is displayed */
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", WIDTH);

        } catch (IOException e) {
            // If another exception is generated, print a stack trace
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);
            // e.printStackTrace();
        }


    }

How do you know it does not run? Is it because it throws an exception?
Does it execute the printStackTrace() when you uncommment it?

Thank you Norm:

I believe line 4 is the problem because the program can't seem to go past it, except when debugging file (Ctrl+Shift+F5). Everything runs just fine on debug file mode.

When running the eproject (F6) it's only exectuted up to line 3:

private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            JOptionPane.showMessageDialog(null, "Line before FileReader", "Just a display BEFORE.", WIDTH);
            FileReader input = new FileReader("projects");
            JOptionPane.showMessageDialog(null, "Line after FileReader", "Just a display AFTER.", WIDTH);
            /* Filter FileReader through a Buffered read to read a line at a
            time */
            BufferedReader bufRead = new BufferedReader(input);

            String line;    // String that holds current file line
            int count = 0;  // Line number of count 

            // Read first line
            line = bufRead.readLine();
            count++;

            // Read through file one line at time. for each project, get the path
            while (line != null) {
                String curr = line.substring(17);
                JOptionPane.showMessageDialog(null, curr, "Line read from file", WIDTH);
                line = bufRead.readLine();
                count++;
            }

            bufRead.close();


        } catch (ArrayIndexOutOfBoundsException e) {
            /* If no file was passed on the command line, this expception is
            generated. A message indicating how to the class should be
            called is displayed */
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", WIDTH);

        } catch (IOException e) {
            // If another exception is generated, print a stack trace
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);
            e.printStackTrace();
        }
    }

This is the output from the compiler ide (ws-run)

init:
Deleting: C:\Users\Carlos\Documents\NetBeansProjects\CelsiusConverterProject\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\Carlos\Documents\NetBeansProjects\CelsiusConverterProject\build\built-jar.properties
compile:
Nothing to copy.
To run this application from the command line without Ant, try:
javaws "C:\Users\Carlos\Documents\NetBeansProjects\CelsiusConverterProject\dist\launch.jnlp"
jnlp:
sign-jars:
generate-jnlp:
Copying 1 file to C:\Users\Carlos\Documents\NetBeansProjects\CelsiusConverterProject\dist
Deleting: C:\Users\Carlos\Documents\NetBeansProjects\CelsiusConverterProject\dist\launch.jnlp_
generate-html-preview:
jar:
jws-run:
BUILD SUCCESSFUL (total time: 1 second)


How do you know it does not run? Is it because it throws an exception?
Does it execute the printStackTrace() when you uncommment it?

So you are saying that when you debug the messages:
Will read file , Done reading file appear
but when you run it, only the first one appears?

I would suggest the following. More debug messages:

File file = new File("projects");
// print the file
// print if the file exists: file.exists()
JOptionPane.showMessageDialog(null, "Will read file", "clear.", WIDTH);
FileReader input = new FileReader(file);
JOptionPane.showMessageDialog(null, "Done reading file", "clear.", WIDTH);

And at the end add another exception:

private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            // ...........
        } catch (ArrayIndexOutOfBoundsException e) {
            /* If no file was passed on the command line, this expception is
            generated. A message indicating how to the class should be
            called is displayed */
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", );

        } catch (IOException e) {
            // If another exception is generated, print a stack trace
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", );
            e.printStackTrace();
        } 
// add this
catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Final error: "+e.getMessage(), "Final Error", );
            e.printStackTrace();
        }
    }

You will also need to check the console or the IDE output when you run it in order to see the printStackTrace or any other messages you print using the System.out.println

JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);

The WIDTH is not correct. Just because it got auto completed from the IDE doesn't mean you should blindly follow it. Check the API of JOptionPane class and check that method as what needs to go there.


Also remove the ArrayIndexOutOfBoundsException. It is never thrown nor you should ever catch it. If you get such exception it means that you made a mistake and read an element from an array or list that exceeded its size and you need to change the code. That is why when you loop you use: int i=0;i<length;i++ So you will not get ArrayIndexOutOfBoundsException.
If you ever get such exception you need to add checks when accessing the element of the array or list, not try to catch. The problem will not go away that way.

Edited 5 Years Ago by javaAddict: n/a

Thank you !
The last catch:

catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Final error: " + e.getMessage(), "Final Error", WIDTH);
            e.printStackTrace();
        }

displays message:
"access denied (java.io.FilePermission projects read"

So is the security that allows access only when debugging. Makes sense :-)

Now I've read that signing the app can cost money or can be an intricate process. Perhaps give permission to one or two files? Any suggestion on where to look for?

Other than that I'd close this thread as Solved.

Thanks a lot !!

Carlos.

Hello.
This java app I'm developing on NetBeans 7.
When i run the project, line 4 below:

FileReader input = new FileReader("projects");

is not executed and apparently stops execution.

Only when debuggin the file or running step by step are the next lines executed.
No execution past line 4, except when debugging.

I've tried with and without the file present, but only when debugging is the line executed, otherwise it just stops.

On the IDE, I've enabled web-star (will deploy that way) and used no codebase for local testing.

Any help greatly appreciated.

private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            JOptionPane.showMessageDialog(null, "Will read file", "clear.", WIDTH);
            FileReader input = new FileReader("projects");
            JOptionPane.showMessageDialog(null, "Done reading file", "clear.", WIDTH);            
        } catch (ArrayIndexOutOfBoundsException e) {
            /* If no file was passed on the command line, this expception is
            generated. A message indicating how to the class should be
            called is displayed */
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", WIDTH);

        } catch (IOException e) {
            // If another exception is generated, print a stack trace
            JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);
            // e.printStackTrace();
        }


    }

Normal applications do not require permission to read file.
Java Applets do require permission.
Is your code an applet?

Hi NormR1;

My code is a java application i want to deploy via WebStart.
As I'm new to java, still not sure if my app qualifies as an applet, it does not run inside the browser, but locally.

As for the access restricion:
I've just found I can self-sign my app by a generated key by specifying so on the project properties | WebStart node.
I ran it and the permission denied is no more.
The compiling however informs:
Warning:
The signer certificate will expire within six months.

So I'd need to check on that too. Don't want to recompile every 6 months.


Thank you again.

Carlos

Normal applications do not require permission to read file.
Java Applets do require permission.
Is your code an applet?

This question has already been answered. Start a new discussion instead.