Results 1 to 17 of 17
  1. #1
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Question Behaviour of the program with Netbeans and without Netbeans different?

    Hello community,
    i have a really strange behaviour of my program.

    I have a program written, that loads data from an csv file into my program.
    This is possible with the library named jCSV (https://code.google.com/p/jcsv/)


    When i start my program with F5 or the PlayButton in Netbeans, my program starts.
    I load the csv data into my program and can go further on.

    I check the data in the program and see, that the data was loaded successfully and also special signs are written correctly.
    For example "Pauls`s Academy" (All special signs are written correctly. UTF-8 conform)


    When I check now the folder dist, there is my program called server.jar with a extra folder lib.
    I start now the program right out the windows explorer. (Without Netbeans)
    The program starts, I load the same csv like before, but after loading I have the strange behaviour that the data is not UTF-8 conform?!?
    When I now have a look at my data I see the same senctence: "Paul<?>s Academy"

    How can that happen, that the program without Netbeans have another behaviour as with Netbeans?
    So and the next question is, how can i solve this? I don`t know where i should have a look or what I should do.

    Hopefully somebody can help me out of here
    Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    What are you using to check the loaded data?
    Is it displayed in a Swing text area, or on the console?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    It is shown up in a Swing text area

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Oh...well there goes my one idea.
    The text area should handle UTF-8, as that's what it works with.
    I know this is the same file being loaded, but is the file UTf-8 or some other character set?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    The file is exported with character st utf-8
    No other program has opened changed the files.

    After that error, when i start netbeans and the program, load the same files again, it is working again X)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    I'm afraid I'm at a loss.
    It's one of those problems that needs you to step through the code and see whether it is during reading in, or writing out, that the problem occurs.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    It's one of those problems that needs you to step through the code and see whether it is during reading in, or writing out, that the problem occurs.
    That could be a problem ;-)
    Because with Netbeans the code and the program are working perfectly.
    When i take only the .jar File and start this one (without Netbeans) than it isn`t working. So no chance to debug

    Maybe there is anybody else here that has a solution?

  8. #8
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Can I push this thread pls (Problem still occures)

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Try debugging the code by adding lots of println() statements that print out the values of variables as they are changed and used.
    Open a command prompt window, change to the folder with the jar file and use the java -jar THEJARFILENAME.jar
    command. The print out will go on the console window. The output should help you understand what the program is doing.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    That is one thing, I also wonder how Netbeans starts the Java application. Which flags are passed to the runtime? Its been a long time since I used Netbeans, but I think somewhere in the project view you can see the exact Java command that will be invoked by Netbeans. But perhaps I now go so far back in time that it was a version of Netbeans that is not designed around ANT.

    I am making a wild guess, but I have a suspicion that Netbeans is overriding the platform default encoding with UTF-8 when running the application.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    So more infos:
    I thought the problem could be in the library i have used (jscv), so i switched to opencsv.
    The same behaviour X/

    Try debugging the code by adding lots of println() statements that print out the values of variables as they are changed and used.
    Open a command prompt window, change to the folder with the jar file and use the java -jar THEJARFILENAME.jar
    command. The print out will go on the console window. The output should help you understand what the program is doing.
    I did this, but the problem is, I think it is not my written code.

    There must be a problem with Netbeans!

    Java Code:
     List<String[]> taenzer;
    reader = new FileReader(file.getAbsolutePath());
    CSVReader csvTanz2TaenerReader = new CSVReader(reader);
    taenzer = csvTaenzerReader.readAll();
    for(String[] temp : taenzer)
    { 
       System.out.println(temp[0]+temp[1]+temp[2]+temp[3]+temp[4]);
    }
    This Code brings me the information with IDE
    012MaxMüstermann

    without IDE:
    012MaxMÄ1/4sstermann

    The library is in the classpath!

    I am making a wild guess, but I have a suspicion that Netbeans is overriding the platform default encoding with UTF-8 when running the application.
    Where can i look at this settings?
    Or where can i define this code?

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Well, that Sysout will print to the console, which will not handle UTF8 anyway.
    It's not much of a test.

    Also, if you're writing to a txt file and then opening in something like NotePad you'll get the same problem.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Normaly I would write the data into a database (hsqldb) instead of "System.out..."
    Java Code:
           for(String[] temp : taenzer)
           {  
              //System.out.println(temp[0]+temp[1]+temp[2]+temp[3]+temp[4]);
              tid = Integer.valueOf(temp[0]); //Check if it is really an integer
              sid = Integer.valueOf(temp[1]);
              nachname = temp[2];
              vorname = temp[3];
              geburtsdatum = temp[4];
                try {
                    sqlFunctions.setExecuteUpdate("INSERT INTO TAENZER "
                            .concat("(taenzerid, SID, VORNAME, NACHNAME, GEBURTSDATUM) VALUES (")
                            .concat(String.valueOf(tid)).concat(",")
                            .concat(String.valueOf(sid)).concat(",'")
                            .concat(vorname).concat("','")
                            .concat(nachname).concat("','")
                            .concat(geburtsdatum).concat("')"));
                                
                } catch (SQLException ex) {
                    throw new StandardException("Error 8725");
                }
                counter++;
           }
    So this is my fully code, so there is no problem!!
    What am I doing wrong?

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Who knows what you're doing wrong. It would benefit you greatly to take this as a hint and research character encoding in general and then how that is applied within the context of Java to gain a better understanding and be able to recognize yourself what you may be doing wrong.

    Until then, all you can do is just try stuff and hope for the best. So try this. Instead of this:

    Java Code:
    reader = new FileReader(file.getAbsolutePath());
    Try this:

    Java Code:
    reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
    FileReader assumes that the file is in the platform encoding, the replacement code specifically dictates that the source file is UTF-8. When it comes to character encoding, its best to be specific.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Thank you all for your help and thank you twice gimbal2 for the Code!!

    With FileInputStream and UTF-8 it is working!!


    Wish you all a nice day

  16. #16
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Crap, you got a code answer and didn't learn anything. This thread is now a failure and its my fault.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  17. #17
    Paul279 is offline Member
    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    0

    Default Re: Behaviour of the program with Netbeans and without Netbeans different?

    Don`t be worry, I have learned out of this situation and have read about InputStreamReader, FileInputStream and FileReader a little bit more ;-)

Similar Threads

  1. Old Java Program in NetBeans
    By Silvia Todorof in forum NetBeans
    Replies: 3
    Last Post: 12-19-2011, 05:08 AM
  2. Written Java Program in Netbeans won't compile..
    By ptrasd12 in forum New To Java
    Replies: 5
    Last Post: 12-01-2011, 02:43 PM
  3. Replies: 2
    Last Post: 03-22-2009, 07:43 PM
  4. netbeans+swing = painting program?
    By yuriythebest in forum New To Java
    Replies: 3
    Last Post: 12-14-2008, 09:55 PM
  5. Program Runs in NetBEans but Not in cmd
    By MeathUltra in forum NetBeans
    Replies: 1
    Last Post: 12-09-2008, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •