This discussion is archived
1 2 Previous Next 27 Replies Latest reply: Jun 25, 2011 5:55 AM by EJP RSS

Some functionalities in JAR do not work

840135 Newbie
Currently Being Moderated
Hello everyone,
I was working on a simple word processor for local language using JTextPane and RTF. The program works fine in Netbeans. But the JAR file does not work. For example, the program has to save to hard disk as well as read from file. The JAR version does not work whereas it works properly in Netbeans. The JAR is created using Netbeans. Can you help me?

Thanks.
  • 1. Re: Some functionalities in JAR do not work
    sabre150 Expert
    Currently Being Moderated
    It is difficult to respond to this without being sarcastic. You have a bug.
  • 2. Re: Some functionalities in JAR do not work
    840135 Newbie
    Currently Being Moderated
    What bug? In IDE, it works fine.
  • 3. Re: Some functionalities in JAR do not work
    EJP Guru
    Currently Being Moderated
    The bug is that the JAR file isn't doing what happens in the IDE environment. Otherwise you aren't actually posting about anything. Bugs can be in build processes as well as program code.

    So what's different between the IDE and the JAR deployment?

    What error do you get?, or what difference between observed and expected behaviour.

    London to a brick something is missing from the JAR file.
  • 4. Re: Some functionalities in JAR do not work
    793415 Pro
    Currently Being Moderated
    lata wrote:
    What bug? ..
    The one that is crashing the code, obviously.
    ..In IDE, it works fine.
    Good for your IDE.

    Something must be different between your (automagic) IDE and running it from the command line.

    -------------------------------------
    For more details on what is failing, try launching the Jar from the command line, to see any stack traces. Also make sure the code does not swallow exceptions.
  • 5. Re: Some functionalities in JAR do not work
    840135 Newbie
    Currently Being Moderated
    Basically, I don't get any error messages. It just fails to do the task properly.
  • 6. Re: Some functionalities in JAR do not work
    840135 Newbie
    Currently Being Moderated
    Let me make the thing clear. The program saves the text in JTextPane to hard disk. The text is wriiten in local language called Amharic (http://en.wikipedia.org/wiki/Amharic_language) which has its own alphabet. I use unicode for this purpose. When the text is saved and read back, it turns out to be garbage (displayed as ??). When I save English, it is normal. This happens in JAR. In IDE, no such problem.

    Edited by: lata on Jun 23, 2011 7:06 AM
  • 7. Re: Some functionalities in JAR do not work
    793415 Pro
    Currently Being Moderated
    lata wrote:
    Let me make the thing clear. The program saves the text in JTextPane to hard disk. The text is wriiten in local language called Amharic which has its own alphabet. I use unicode for this purpose. When the text is saved and read back, it turns out to be garbage (displayed as ??). When I save English, it is normal. This happens in JAR. In IDE, no such problem.
    It would seem the character encoding is wrong, but I don't have much experience with that.
  • 8. Re: Some functionalities in JAR do not work
    sabre150 Expert
    Currently Being Moderated
    >
    It would seem the character encoding is wrong, but I don't have much experience with that.
    And even if you had Andrew, 'lata' is drip feeding information about the problem. We are not mind readers and we don't have crystal balls but I'm 100% sure that the wrong character encoding is being used but without seeing how 'lata' is writing and reading the data it is impossible for us (well me anyway) to say exactly what he is doing wrong.
  • 9. Re: Some functionalities in JAR do not work
    793415 Pro
    Currently Being Moderated
    sabre150 wrote:
    >
    It would seem the character encoding is wrong, but I don't have much experience with that.
    And even if you had Andrew, 'lata' is drip feeding information about the problem.
    <drily>Maybe that is because the OP wants to liven up our day by allowing us to play '20 questions'.</drily> I don't think they'll get many takers.
  • 10. Re: Some functionalities in JAR do not work
    840135 Newbie
    Currently Being Moderated
    sabre150 wrote:
    >
    It would seem the character encoding is wrong, but I don't have much experience with that.
    And even if you had Andrew, 'lata' is drip feeding information about the problem. We are not mind readers and we don't have crystal balls but I'm 100% sure that the wrong character encoding is being used but without seeing how 'lata' is writing and reading the data it is impossible for us (well me anyway) to say exactly what he is doing wrong.
    Here is the code:
    public void saveFile()
        {
            try
            {
                String written;
                char tofile[];
                int i = 0;
    
                written = editor.document.getText();
                written = editor.doc.getText(0, editor.doc.getLength());
                tofile = new char[written.length()];
                written.getChars(0, written.length(), tofile, 0);
    
                FileWriter out = new FileWriter(saveFileName);
                BufferedWriter writer = new BufferedWriter(out);
                writer.write(tofile);
                writer.close();
                fileSaved = true;
            }
            catch(IOException xx){
                info(xx.toString());
            }
            catch(BadLocationException xx){
                info(xx.toString());
            }
        }
        public void readFile()
        {
            try
            {
                String symbol = new String();
                FileReader in = new FileReader(openFileName);
                BufferedReader reader = new BufferedReader(in);
    
                //clear previous content
                editor.document.setText("");
                while(true)
                {
                    symbol = reader.readLine();
                    if(symbol == null) //EOF reached
                        break;
                    
                    symbol = symbol + "\n";
                    editor.doc.insertString(editor.doc.getLength(), symbol, null);
                }
                reader.close();
                //editor.info("Read successfully!");
            }
            catch(IOException xx){
                info(xx.toString());
            }
            catch(BadLocationException xx){
                info(xx.toString());
            }
        }
    Edited by: lata on Jun 20, 2011 4:31 AM

    Edited by: lata on Jun 20, 2011 8:48 AM
  • 11. Re: Some functionalities in JAR do not work
    sabre150 Expert
    Currently Being Moderated
    1) We have no idea what class instance 'editor' references.
    2) Always specify the character encoding when reading and writing characters or you will be using the default character encoding which may or may not support the characters to are working with. You will need to use OutputStreamWriter and InputStreamReader so as to be able to specify the character encoding. I would suggest you use "utf-8" since that will work for all UNICODE characters.
    3) Your exception handling throws away most of the useful information. Most logging system allow one to pass an exception without having to convert to a String.
    4) Please use
     tags to make code readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  • 12. Re: Some functionalities in JAR do not work
    840135 Newbie
    Currently Being Moderated
    1) We have no idea what class instance 'editor' references.
    It is the name of the class in which JTextPane and RTFEditorKit is declared and created.
    package unicoder;
    import javax.swing.text.*;
    import javax.swing.text.rtf.*;
    import javax.swing.undo.*;
    import javax.swing.event.*;
    import java.io.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Editor extends JFrame
    {
        BufferedImage icon;
        Actor listen;
        Keyboard key;
        CaretChange caret;
        Windower close;
        JMenuBar menuBar;
        MenuBar mbar;
        Services services;
        public UndoManager undoManager;
        public JTextPane document;
        public RTFEditorKit rtfEditor;
        public StyledDocument doc;
        public StyleContext scontext;
        public MutableAttributeSet attribute;
        public Dimension screenSize;
        int X = 640, Y = 480; //default screen size
        JScrollPane scroll;
        JRadioButton english, amharic;
        Font font;
        boolean writeEnglish = false;
    2) Always specify the character encoding when reading and writing characters or you will be using the default character encoding which may or may not support the characters to are working with.
    I think that is a good point. I will check that out.
    3) Your exception handling throws away most of the useful information. Most logging system allow one to pass an exception without having to convert to a String.
    I accept that but I don't get any error message, you see. It is silent problem.
    4) Please use
     tags to make code readable.
    {quote:title=sabre150 wrote:}{quote}
    Thanks. I am not familiar with the editor/the tags.
  • 13. Re: Some functionalities in JAR do not work
    sabre150 Expert
    Currently Being Moderated
    lata wrote:
    2) Always specify the character encoding when reading and writing characters or you will be using the default character encoding which may or may not support the characters to are working with.
    I think that is a good point. I will check that out.
    Since you are handling RTF this may no longer be relevant but it can't hurt specifying utf-8.

    >
    3) Your exception handling throws away most of the useful information. Most logging system allow one to pass an exception without having to convert to a String.
    I accept that but I don't get any error message, you see. It is silent problem.
    That doesn't make your exception handling valid.

    Why are you not making use of the read and write method of RTFEditorKit? These would get rid of most of your code and probably solve the encoding problem.
  • 14. Re: Some functionalities in JAR do not work
    840135 Newbie
    Currently Being Moderated
    3) Your exception handling throws away most of the useful information. Most logging system allow one to pass an exception without having to convert to a String.
    I accept that but I don't get any error message, you see. It is silent problem.
    That doesn't make your exception handling valid.
    What exactly should I do to handle the exception properly?
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points