Hallo, ich bin gerade dabei ein kleines Programm zu schreiben, aber leider wird nun bei diesem Programm die benötigte JScrollPane nicht angezeigt.
Hier ist mein Code:
Das JEditorPane editNews wird in einer anderen Klasse hinzugefügt zum Window.
Für eine Sekunde erscheint beim Start der Anwendung ein Fehler und im Debug-Mode steht unter Breakpoint automatisch: "ArrayIndexOutOfBoundsException:caught and uncaugt" und "NullPointerException: caught and uncaught".
Leider kann ich mit diesen Fehlern nichts anfangen, da keine Zeilenangaben vorhanden sind und ich nicht weiss was diese Bedeuten.
Zudem wird ein Button auch nicht angezeigt:
Ich hoffe ihr könnt mir hierbei helfen.
JavaGamer
Hier ist mein Code:
Java:
public class NewsHandler
{
private String file = "news.html";
public NewsHandler()
{
this.getNews();
}
@SuppressWarnings("unused")
private void getNews()
{
// sets the editable to false for the JEditorPane that you could not edit it
Launcher.editNews = new JEditorPane();
Launcher.editNews.setEditable(false);
Launcher.editNews.setBackground(Color.DARK_GRAY);
Launcher.editNews.setSize(858, 284);
Launcher.editNews.setBounds(0, 60, 858, 319);
//news.setBounds(0, 60, 429, 319);
java.io.File nfile = new java.io.File(file);
// checks if the file exits
if(nfile.isFile() || !nfile.canRead())
{
// sets the URL (location for the .html file)
try
{
//java.net.URL newsURL = new java.net.URL(file);
File newsURL = new File(file);
if(newsURL != null)
{
try
{
Launcher.editNews.setPage(newsURL.toURI().toURL());
}
catch (IOException ex)
{
JOptionPane.showMessageDialog(null, "Attempted to read a bad URL: " + newsURL, "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
else
{
JOptionPane.showMessageDialog(null, "Couldn't find file: " + file, "Error", JOptionPane.ERROR_MESSAGE);
}
//java.net.URL helpURL = NewsHandler.class.getResource("TextSamplerDemoHelp.html");
}
catch (/*MalformedURLException e*/ Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
finally
{
//Put the editor pane in a scroll pane.
//JScrollPane editorScrollPane = new JScrollPane(Launcher.editNews);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(Launcher.editNews);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
//scrollPane.setPreferredSize(new Dimension(250, 145));
//scrollPane.setMinimumSize(new Dimension(10, 10));
}
}
else
{
this.downloadNews();
}
}
Für eine Sekunde erscheint beim Start der Anwendung ein Fehler und im Debug-Mode steht unter Breakpoint automatisch: "ArrayIndexOutOfBoundsException:caught and uncaugt" und "NullPointerException: caught and uncaught".
Leider kann ich mit diesen Fehlern nichts anfangen, da keine Zeilenangaben vorhanden sind und ich nicht weiss was diese Bedeuten.
Zudem wird ein Button auch nicht angezeigt:
Java:
// sets the size of the box and the color of the frame (= Rahmen)
this.play.setSize(125, 568);
this.play.setBorder(BorderFactory.createLineBorder(Color.BLUE));
this.play.setBounds(0, 379, 858, 70);
Java:
this.play.add(launch);
Java:
if(nwpanelbl == true && otpanelbl == false && mdpanelbl == false && txpanelbl == false)
{
new volcanoplayer.launcher.news.NewsHandler();
//panel.remove(packs);
//panel.remove(info);
nwpanel.setBackground(Color.DARK_GRAY);
nwpanel.setLayout(null);
nwpanel.add(Launcher.editNews);
nwpanel.add(options);
nwpanel.add(play);
frames.getContentPane().add(nwpanel);
//panel.add(nwpanel);
//nwpanel.validate();
//panel.validate();
}
Ich hoffe ihr könnt mir hierbei helfen.
JavaGamer