Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems trying to use JEditorPane Class

0 views
Skip to first unread message

Chris Williams

unread,
Jun 3, 1999, 3:00:00 AM6/3/99
to
I am trying to use the JEditorPane class to display some basic text files.
Every time i try, I keep getting a NULL pointer error. Here is my code and
output.

////////////////////CODE
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.io.*;

public class TJEditorPane extends JFrame
{
public TJEditorPane()
{
super( "Test Editor Pane" );
Container container = this.getContentPane();

JEditorPane editorPane;

File file = new File( "c:\\sms.ini" );
try
{
if( file.exists() )
{
System.out.println( "File: " + file.getPath() );
System.out.println( "URL: " + file.toURL() );
editorPane = new JEditorPane( file.toURL() );
container.add( editorPane );
//editorPane.setPage( file.toURL() );
//FileInputStream stream = new FileInputStream( file );
//editorPane.read( stream, "Test Stream" );
}
}
catch( Exception e )
{
System.out.println( "Exception: " + e );
}
show();
}

public static void main( String[] args )
{
new TJEditorPane();
}
}

/////////////OUTPUT
File: c:\sms.ini
URL: file:/c:/sms.ini
java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:124)
at
javax.swing.JEditorPane.createEditorKitForContentType(JEditorPane.java:849)
at
javax.swing.JEditorPane.getEditorKitForContentType(JEditorPane.java:741)
at javax.swing.JEditorPane.setContentType(JEditorPane.java:645)
at javax.swing.JEditorPane.getStream(JEditorPane.java:483)
at javax.swing.JEditorPane.setPage(JEditorPane.java:309)
at javax.swing.JEditorPane.<init>(JEditorPane.java:174)
at TJEditorPane.<init>(TJEditorPane.java:24)
at TJEditorPane.main(TJEditorPane.java:41)

The file exists and I do have read permission on it. Any help in figuring
out what is wrong would be great!!
Thanks
Chris

Chris Williams

unread,
Jun 4, 1999, 3:00:00 AM6/4/99
to
Looks like after some trial and error.....the editor pane relies on using
the file extension of the file to determine the type. Once I set the text
file to have a .txt at the end..it worked fine.

Chris Williams <will...@mail.northgrum.com> wrote in article
<01beade9$1d357360$8168e484@pc3535>...

0 new messages