Click to See Complete Forum and Search --> : JTextPane Help


N.BALAMURUGAN
March 16th, 1999, 10:45 AM
I am developing an Editor using Swing and facing the following problem.

It would be of great help if u can throw some light on it.


I have a problem in saving a Document in Rich Text Format from

JTextPane. I am getting the following Exception.


****************************************************************************


reading charset ansi

Error while Saving : java.io.IOException: Unable to read from character set

file (java.lang.NullPointerException)


**********************************************************************


Please guide me to resolve this problem.The Code Snippet is given at

the end.



***************************************SAVE CODE*******************************


void jbSave_actionPerformed(ActionEvent e) {

if (fileDialog == null)

{

fileDialog = new FileDialog(this);

}

fileDialog.setMode(FileDialog.SAVE);

fileDialog.show();

String file = fileDialog.getFile();

String dir = fileDialog.getDirectory();

File f = new File(dir,file);

try {

OutputStream out = new FileOutputStream(f);

rtfeditor.write(out,dsd,0,dsd.getLength());

out.close();

}

catch (Exception exSave)

{

System.out.println(" Error while Saving : " + exSave);

}

}


*************************OPEN CODE********************************************


void jbOpen_actionPerformed(ActionEvent e) {

fileDialog.setMode(FileDialog.LOAD);

fileDialog.show();


String file = fileDialog.getFile();

String dir = fileDialog.getDirectory();

File f = new File(dir,file);


try {

InputStream in = new FileInputStream(f);

rtfeditor.read(in,dsd,0);

textPane.setDocument(dsd);

in.close();

}

catch (Exception exOpen)

{

System.out.println(" Error while Opening : " + exOpen);

}


}


*****************************************************************************