Hi all,
Thanks in advance. I am new at Java. Currently I'm having two java files one is applet. when i try to preview the applet i get an error like this :
java.lang.NullP ointerException
at java.util.Hasht able.put(Unknow n Source)
at javax.swing.JEd itorPane.regist erEditorKitForC ontentType(Unkn own Source)
at javax.swing.JEd itorPane.regist erEditorKitForC ontentType(Unkn own Source)
at javax.swing.JEd itorPane.loadDe faultKitsIfNece ssary(Unknown Source)
at javax.swing.JEd itorPane.getKit TypeRegistry(Un known Source)
at javax.swing.JEd itorPane.getEdi torKitClassName ForContentType( Unknown Source)
at javax.swing.JTe xtPane.<init>(U nknown Source)
what i'm doing wrong?pls help me guys...thanks
21 4031 JosAH 11,448
Recognized Expert MVP
Can you show a bit of (relevant) code please? btw, I changed your topic titile
to something more to the point.
kind regards,
Jos
because you pointed to hashtable that doesn't have the key ?
check your code that use that hashtable ...
Hi all,
Thanks Josah. Erm, what do you mean by hashtable nick?I don't understand..Sor ry.btw this is my code that call JTextPane
code :
private JTextArea textArea = null;
private JTextPane resultArea = null;
private JComboBox langBox = null;
private Map<Language, ConfigurationDi alog> configDialogs = new HashMap<Languag e, ConfigurationDi alog>();
public void createAndShowGU I(String inputText) {
JFrame frame = new JFrame("Test");
frame.setDefaul tCloseOperation (JFrame.HIDE_ON _CLOSE);
textArea = new JTextArea(input Text);
// TODO: wrong line number is displayed for lines that are wrapped automatically:
textArea.setLin eWrap(true);
textArea.setWra pStyleWord(true );
resultArea = new JTextPane();
resultArea.setC ontentType("tex t/html");
resultArea.setT ext("Results will appear here");
JLabel label = new JLabel("Please type or paste text to check in the top area");
JButton button = new JButton("Check text");
button.setMnemo nic('c');
button.addActio nListener(this) ;
Hi all,
Thanks Josah. Erm, what do you mean by hashtable nick?I don't understand..Sor ry.btw this is my code that call JTextPane
code :
private JTextArea textArea = null;
private JTextPane resultArea = null;
private JComboBox langBox = null;
private Map<Language, ConfigurationDi alog> configDialogs = new HashMap<Languag e, ConfigurationDi alog>();
public void createAndShowGU I(String inputText) {
JFrame frame = new JFrame("Test");
frame.setDefaul tCloseOperation (JFrame.HIDE_ON _CLOSE);
textArea = new JTextArea(input Text);
// TODO: wrong line number is displayed for lines that are wrapped automatically:
textArea.setLin eWrap(true);
textArea.setWra pStyleWord(true );
resultArea = new JTextPane();
resultArea.setC ontentType("tex t/html");
resultArea.setT ext("Results will appear here");
JLabel label = new JLabel("Please type or paste text to check in the top area");
JButton button = new JButton("Check text");
button.setMnemo nic('c');
button.addActio nListener(this) ;
1.) Please use code tags when posting code.
2.) If you look at that stacktrace again, you'll see that it tells you the exact line number where that exception was thrown. That line and the code lines around it are the relevant code that Jos asked you to post.
oh...thanks guys,
ok...here is the code that is relevant to the trace and the full trace
trace : -
-
Java Plug-in 1.6.0_02
-
Using JRE version 1.6.0_02 Java HotSpot(TM) Client VM
-
User home directory = C:\Documents and Settings\Administrator
-
network: Loading user-defined proxy configuration ...
-
network: Done.
-
network: Loading proxy configuration from Internet Explorer ...
-
network: Done.
-
network: Loading direct proxy configuration ...
-
network: Done.
-
network: Proxy Configuration: No proxy
-
-
-
----------------------------------------------------
-
c: clear console window
-
f: finalize objects on finalization queue
-
g: garbage collect
-
h: display this help message
-
l: dump classloader list
-
m: print memory usage
-
o: trigger logging
-
p: reload proxy configuration
-
q: hide console
-
r: reload policy configuration
-
s: dump system and deployment properties
-
t: dump thread list
-
v: dump thread stack
-
x: clear classloader cache
-
0-5: set trace level to <n>
-
----------------------------------------------------
-
-
liveconnect: Invoking JS method: document
-
liveconnect: Invoking JS method: URL
-
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@12498b5, refcount=1
-
basic: Added progress listener: sun.plugin.util.GrayBoxPainter@f5da06
-
basic: Loading applet ...
-
basic: Initializing applet ...
-
basic: Starting applet ...
-
basic: completed perf rollup
-
liveconnect: Invoking method: public void test.check(java.lang.String)
-
liveconnect: Needs conversion: java.lang.String --> java.lang.String
-
java.lang.NullPointerException
-
at java.util.Hashtable.put(Unknown Source)
-
at javax.swing.JEditorPane.registerEditorKitForContentType(Unknown Source)
-
at javax.swing.JEditorPane.registerEditorKitForContentType(Unknown Source)
-
at javax.swing.JEditorPane.loadDefaultKitsIfNecessary(Unknown Source)
-
at javax.swing.JEditorPane.getKitTypeRegistry(Unknown Source)
-
at javax.swing.JEditorPane.getEditorKitClassNameForContentType(Unknown Source)
-
at javax.swing.JTextPane.<init>(Unknown Source)
-
at mypack.Main.createAndShowGUI(main.java:84)
-
at mypack.Main.openGui(main.java:236)
-
at test.check(test.java:27)
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
-
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
-
at java.lang.reflect.Method.invoke(Unknown Source)
-
at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
-
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
-
at java.lang.reflect.Method.invoke(Unknown Source)
-
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
-
at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
-
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
-
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
-
at java.security.AccessController.doPrivileged(Native Method)
-
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
-
java.lang.Exception: java.lang.NullPointerException
-
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
-
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
-
at java.security.AccessController.doPrivileged(Native Method)
-
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
-
-
and the relevant code is : -
private JTextArea textArea = null;
-
private JTextPane resultArea = null;
-
private JComboBox langBox = null;
-
-
private Map<Language, ConfigurationDialog> configDialogs = new HashMap<Language, ConfigurationDialog>();
-
-
public Main() {
-
}
-
-
public void createAndShowGUI(String inputText) {
-
JFrame frame = new JFrame("Grammar Check Tool");
-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-
textArea = new JTextArea(inputText);
-
// TODO: wrong line number is displayed for lines that are wrapped automatically:
-
textArea.setLineWrap(true);
-
textArea.setWrapStyleWord(true);
-
JTextPane resultArea = new JTextPane();
-
resultArea.setContentType("text/html");
-
resultArea.setText("Results will appear here");
-
JLabel label = new JLabel("Please type or paste text to check in the top area");
-
JButton button = new JButton("Check text");
-
button.setMnemonic('c');
-
button.addActionListener(this);
-
-
JButton configButton = new JButton(OPTIONS_BUTTON);
-
configButton.setMnemonic('o');
-
configButton.addActionListener(this);
-
-
JPanel panel = new JPanel();
-
panel.setLayout(new GridBagLayout());
-
GridBagConstraints buttonCons = new GridBagConstraints();
-
buttonCons.gridx = 0;
-
buttonCons.gridy = 0;
-
panel.add(button, buttonCons);
-
buttonCons.gridx = 1;
-
buttonCons.gridy = 0;
-
panel.add(new JLabel(" "), buttonCons);
-
buttonCons.gridx = 2;
-
buttonCons.gridy = 0;
-
-
buttonCons.gridx = 3;
-
buttonCons.gridy = 0;
-
buttonCons.insets = new Insets(0, 10, 0, 0);
-
//panel.add(configButton, buttonCons);
-
-
Container contentPane = frame.getContentPane();
-
GridBagLayout gridLayout = new GridBagLayout();
-
contentPane.setLayout(gridLayout);
-
GridBagConstraints cons = new GridBagConstraints();
-
cons.fill = GridBagConstraints.BOTH;
-
cons.weightx = 10.0f;
-
cons.weighty = 10.0f;
-
cons.gridx = 0;
-
cons.gridy = 0;
-
contentPane.add(new JScrollPane(textArea), cons);
-
cons.gridy = 1;
-
cons.weighty = 5.0f;
-
contentPane.add(new JScrollPane(resultArea), cons);
-
-
cons.fill = GridBagConstraints.NONE;
-
cons.gridx = 0;
-
cons.gridy = 2;
-
cons.weighty = 0.0f;
-
cons.insets = new Insets(3,3,3,3);
-
//cons.fill = GridBagConstraints.NONE;
-
contentPane.add(label, cons);
-
cons.gridy = 3;
-
contentPane.add(panel, cons);
-
-
frame.pack();
-
frame.setSize(600, 600);
-
frame.setVisible(true);
-
}
-
-
Thanks for your help...
JosAH 11,448
Recognized Expert MVP
Which of the lines is line #84 in method createAndShowGU I()?
kind regards,
Jos
Which of the lines is line #84 in method createAndShowGU I()?
kind regards,
Jos
resultArea = new JTextPane();
regards,
teenICe
Here is one nit that is a good recipe for brewing nullpointers.
You have - JTextPane resultArea = new JTextPane();
inside your createGUI method. This hides the resultArea already defined in the class using - private JTextPane resultArea = null;
. The later resultArea variable is thus probably not being initialized properly.
JosAH 11,448
Recognized Expert MVP
resultArea = new JTextPane();
regards,
teenICe
Got it: you have a member variable resultArea but you also define a local variable
with the same name; it effectively hides the member variable which will remain
null all the time. Don't define that local variable.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: gabryh |
last post by:
Hi,
The following code throws me NullPointerException.
.....
public static boolean isEmpty(String value) {
return ((value == null) || (value.trim().equals("")));
}
|
by: Smith |
last post by:
The program compiled successfully,
but it gives the following error on runtime....
java.lang.NullPointerException
at FrogManiaApp.paint(FrogManiaApp.java:102)
at sun.awt.RepaintArea.paint(RepaintArea.java:177)
at
sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
at java.awt.Component.dispatchEventImpl(Component.java:3678)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
|
by: Ike |
last post by:
I have a signed JApplet which has a JTextArea wherein one can put Jython
Script. Upon clicking a JButton, the script is executed. The script which
executes to code is listed below.
If I run the Applet in an AppletViewer, it runs fine. However, when run in a
web browser, I am getting NullPointerException's (I copy-pasted from the
Java Console these Exceptions). Please Note, I AM including jython.jar in
the ARCHIVE parameter of the HTML...
|
by: oll3i |
last post by:
nevermind the previous prob i posted
i m getting further and i get a new exception
in readFile method pleae help me with that one
thank u a lot in advance
java.lang.NullPointerException
at konta_bankowe.Interfejs.readFile(Interfejs.java)
at konta_bankowe.Interfejs.wyswietlHistorieRachunku(Interfejs.java)
at konta_bankowe.Interfejs.access$0(Interfejs.java)
|
by: gezkk |
last post by:
hi,
i m using http proxy service to get proxy and host to applet,
its working fine with jdk1.5 but getting java.lang.NullPointerException in jdk1.6
And the following is mseeage contains java console
java.lang.NullPointerException
at
com.atonesoftware.web.applet.transfer.client.http.HTTPTransfer.autoDetectProxy(HTTPTransfer.java:326)
| |
by: speedygonzalez |
last post by:
Hi all!
I've a pretty naive problem with my applet which is as follows.....
// Wordlist for GRE High Frequency Words
import java.awt.*;
import java.applet.*;
|
by: pradeep84 |
last post by:
hi all,
i'm using the following code and i'm getting
exception in thread "main" java.lang.nullpointerexception at the line which is in bold. help me to solve this problem
import java.applet.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.sql.*;
|
by: ketand1 |
last post by:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.*;
class DbAwt extends Frame implements ActionListener
{
private TextField t1, t2, t3;
|
by: sokeefe |
last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that already exist) in my application using the Design Editor.
I go about this by right-clicking on the JButton in the design editor, navigating to Events -> Action -> actionPerformed. The auto-generated code appears for a brief moment before it...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |