Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HTMLEditorKit Reading Problems



Hi,

We are developing an HTML Editor and are trying examples out of different books. The most appealing code is in Swing 2 by Robinson and Vorobiev. The code reads text files without difficulty. Unfortunately the code always breaks reading HTML files.

The example (20.1) declares and intializes the key variables at class level:
// Make sure we install the editor kit before creating
// the initial document.
m_editor = new JTextPane();
m_kit = new HTMLEditorKit();
m_editor.setEditorKit(m_kit);

All works fine until I reach the method that reads in HTML documents.

try
{
InputStream in = new FileInputStream(m_currentFile);
m_doc = (HTMLDocument) m_kit.createDefaultDocument();
m_kit.read(in, m_doc, 0); // Code breaks here!!!
m_context = m_doc.getStyleSheet();
m_editor.setDocument(m_doc);
in.close();
} catch (Exception ex)
{
showError(ex, "Error reading file " + m_currentFile);
}

When I debug, I can confirm that the file names and paths are OK and that the input stream is not null. The kit throws a mysterious javax.swing.text.ChangedCharSetException
at javax.swing.text.html.parser.DocumentParser.handleEmptyTag(DocumentParse r.java:169)...

I have no idea how to deal with the exception.

Any help will be greatly appreciated!

Mark
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.