Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

FileDialog: option to select both files AND directories?

843807Sep 21 2010 — edited Sep 23 2010
Hi,

For the sake of Mac users I wish to use FileDialog for file/directory selection. I can use:

System.setProperty(apple.awt.fileDialogForDirectories, true)

in order to be able to select directories, but it only allows directory selection. Not setting it only allows file selection. I wish to be able to select either a file OR a directory, which I haven't found a way to do with FileDialog.

Anyone know how?

thanks, Allasso

Comments

handat

Why do you have a semicolon after the function body for Arraylist2Decimal()?

}};

mNem

static void Arraylist2Decimal() {

        for (int i = 1; i == SEPARATED1.size() + 1; i++) {

Here, i is initialized to 1.

the testing condition for the FOR loop to iterate is set to i == the size of SEPARATED1 plus 1. So only if the size of SEPERATED1 is 0 it will meet the condition to go into the loop.

Change it to

  for (int i = 1; i <= SEPARATED1.size() + 1; i++) {

mNem

for (int i = 1; i == SEPARATED1.size() + 1; i++) {

            int intValue = (int) SEPARATED1.get(i);

Point - 1:

ArrayList indexing starts at 0.

If you loop starting at 1, you will be ignoring the first value in the arraylist.

Point -2 :

The loop is set to run until i == SEPARATED1.size() + 1, which is one index more than the size. This will throw an exception.

It should be

for (int i = 0; i <= SEPARATED1.size() + 1; i++) {

unknown-7404

but what happened, is that my program completely ignores the "Arraylist2Decimal" method even after called.

I will be really grateful if someone could help me.

(Using netbeans IDE)

All you have to do is step through the code one line at a time and watch/examine what is happening.

If you need help using the debugger in NetBeans read the documentation and then post your question on a NetBeans forum.

Dynami

Thanks for all the help. Every single answer above was right(But now I'm not sure on what answer I should tag as the correct answer.). after implementing the changes, now my code works fine.

And specially to rp0428 for telling me about the debugger. If you didnt tell me about this, I would never know that the arraylist starts at 0 while its size starts counting at 1.

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 21 2010
Added on Sep 21 2010
5 comments
3,029 views