JFrame will not close giving null pointer exception
Hello ev1, Heres what I'm doing, I have a menu with JButtons that when pressed will take you to a game (this works fine). When your done with the game, you press a button that closes the JFrame(game) and starts the menu again (this gives the error null pointer exception). Heres a brief summary of the design:
FullScreenSetup class
has openWindow() that sets up a new full screen JFrame. (works)
has closeWindow() that removes everything in the contentPane and sets
visible(false).
GameMenu class
uses FullScreenSetup via FullScreenSetup window;
uses window.openWindow() to set up the window.
also sets up the buttons and handles them when pressed
VideoPoker class (the game)
uses FullScreenSetup via FullScreenSetup window;
runs the game and has the button that should close the window and go
back to the menu.
heres how i thought it should work, in the actionPerformed method I have
window.closeWindow(); <- this gives me the error
new GameMenu(); <- this is my ultimate goal (hopefully brings me
back to the menu screen to choose another game)
I hope what I have written is enough for someone to help me because I know what it is like to read through hundreds of lines of code to help someone. Thx.
What I cannot understand is that when going from the menu to the game I use window.closeWindow(); so that I can clear the menu and paste the game on the screen this works fine. so why does it not work a second time?
Similar Messages
-
Incomplete instances for multiuser login giving null pointer exception error
Hi
I am facing one problem about Weblogic workflow. We have developed an application
where number of users logs in simultaneouly.
When a user logs in, one instance of workflow gets created. So when more than one
user logs in, that many instanaces gets created. But it gives us the error like "Null
pointerexception". This is beacuse The instanaces which gets created were not getting
completed, they are incomplete. And when I delete these incomplete instances and
try to login one after another user, it works fine. But again when two or more users
logs in at same time we get the same error.
Can you please help me out solving this problem.
Regards,
Rajesh PatilI have just found out that when this error appear, a folder called splash is created in the same directory as my project folder and the application that I just ran has appeared in there and I can run it from the files in that folder. I can't see anywhere in my code which specifies sending these files to a splash folder.
Does anyone know why this might happen and if this is related to the Null Pointer Exception Error?
-Mark -
Dump at if condition statement. Null pointer Exception
hi all,
I have a recursive node as a child node for a value node. I have created an instance of the value node.
I also have accessed current elem of this value node. Since every elem of this value node will have recursive node also in it, I want to access the recursive node present in the elem.
I want to do this using general node and element API - ie IWDNode and IWDNodeElement.
No specific node name can be used coz this is done for a generic method which takes a value node a as parameter and tries to create child elems for the node accessing the recursive node present in it.
How can this be done ?
I am using the following code.
String ChildName = SourceNode.getNodeInfo().getName().split("_")[1] + "Rec";
IWDNode childNode = SourceNode.getChildNode(ChildName, 0);
if (childNode == null || childNode.size() == 0 ) {
It throws a dump at if condition statement. ( Null pointer Exception)
Any help appreciated !!
Edited by: ymb on Mar 25, 2009 1:23 PMHi,
Its actually pity simple. If you will read the Javadocs you will find that there are various ways in which you can get the list of all chil nodes of a parent node.
You just have to iterate over the chil nodes and get the names of the node.
Please check this link for JAVA docs: http://help.sap.com/javadocs/nwce/current/wdr/index.html
However for your requirement there can be following ways to get the list of the chil nodes. Please check these two code snippets:
IWDNode node = wdContext.nodeNode1();
Iterator itr = node.getNodeInfo().iterateChildren();
String nodeName = null;
String parentName = null;
while(itr.hasNext()){
nodeName = ((IWDNode)itr.next()).getNodeInfo().getName();
parentName = ((IWDNode)itr.next()).getNodeInfo().getParent().getName();
wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Node Name is: "
+ nodeName +"and it is under the parent Node named: " +parentName);
Also there is another approach to do teh same, please have a look to this code snippet:
List list = node.getNodeInfo().getChildren();
String nodeName = null;
String parentName = null;
Iterator itr1 = list.iterator();
while (itr1.hasNext()) {
nodeName = ((IWDNode) itr1.next()).getNodeInfo().getName();;
parentName = ((IWDNode)itr1.next()).getNodeInfo().getParent().getName();
wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Node Name is: "
+ nodeName +"and it is under the parent Node named: " +parentName);
I am sure this will all your issues and also you will not get the null pointer exception which was your initial issue.
Please revert back in case you have any further issues.
Thanks and Regards,
Pravesh -
Null pointer exception while inserting a new row in ADF with jdev
Hi,
In ADF, I have retrieved some user information from LDAP server and I want to insert those values in to my table. But when I do this, I am getting a null pointer exception when I get the view object (ViewObject vo=getCRUIP002_1();). I am not sure why this happens.
Here is my code. It is urgent.
and please some one help me in fixing the issue.
ViewObject vo=getCRUIP002_1();
vo.clearCache();
vo.setMaxFetchSize(0);
vo.executeQuery();
Row newRow=vo.createRow();
vo.insertRow(newRow);
SearchResult res = (SearchResult)results.next();
Attributes attrs = res.getAttributes();
// Row newRow = vo.getCurrentRow();
newRow.setAttribute("LOGINNAME",(Object)attrs.get("sn").get().toString());
newRow.setAttribute("PASSWORDVALUE","x");
newRow.setAttribute("FIRSTNAME",(Object)attrs.get("sn").get().toString());
newRow.setAttribute("LASTNAME",(Object)attrs.get("sn").get().toString());
newRow.setAttribute("EMAIL",(Object)attrs.get("mail").get().toString());
Thanks,
Priya.Sassuming ur jdev version is 10.1.2
ViewObject vo=getCRUIP002_1();i dont think ur getting the view object hence null pointer expception.
ViewObject vo = findViewObject("MyView1");
if u r in the object class then first get the root application module and then access the View obejct from there.
In ADF if u assign a null value, u will always get the null pointer exception coz of java. Run the app in debug mode and check the values step by step, by the way there is not exception handling in ur code either, Do u know how to debug in Jdev ?
zaibi. -
Problem in getEelementById() method-null pointer exception
Hi All,
I am using DocumentBuilder factory for parsing a xml file.
I am getting the document object and also creating an element in
the root element .And also I am setting the element id for the
element as attiribute .I need to select the element having same ID
using getElementById() method .But it is giving null pointer
exception.
N.B: My parsing file contains dtd declaration and root element.
My sample code look like this;
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(ne File("C:/index.xml");
Element root t=doc.getDocumentElement();
root.setAttribute("ID","12345");
Element oElement = doc.createElement(element_name);
oElement.setAttribute("ID",element_id);
Element oEle=doc.getElementById(element_id);
Could anyone please to solve this problem.
Please do favour with me.
Thanks and Regards,
Sreekanthwhile creating xml you should mention which attribute is ID attribute using
setIDAttribute() method,
as you are setting "ID" attribute as ID so
after adding Id attribute to the root element
use setIDAttribute("ID",true);
then getElementById will return the element by using ID
regards
shivakumar.T -
Null pointer exception in ISimpleTypeModifiable
Hi
I am trying to add values to dropdownbykey dynamically using this code:
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("PROCESS");
ISimpleTypeModifiable processType = attributeInfo.getModifiableSimpleType();
processType.setFieldLabel("PROCESS");
IModifiableSimpleValueSet valueSet = processType.getSVServices().getModifiableSimpleValueSet();
Code is giving null pointer exception in the following line:
ISimpleTypeModifiable processType = attributeInfo.getModifiableSimpleType();
How to Solve it.Its urgent.
Points will be awarded.Actually the process is the attribute of node within context.
so i changed the code to:
IWDAttributeInfo attributeInfo = wdContext.nodeAuditNode().getNodeInfo().getAttribute("PROCESS") ;
ISimpleTypeModifiable processType = attributeInfo.getModifiableSimpleType();
processType.setFieldLabel("PROCESS");
IModifiableSimpleValueSet valueSet = processType.getSVServices().getModifiableSimpleValueSet();
The second point is: we can't modify the data type of mapped attribute in view controller.
So for that, we have to write that code in component controller. -
Null Pointer exception in accessing EJB in 9.0.3
Hi
The application is working fine with 9.0.2, but when I deployed in 9.0.3 it is giving Null Pointer Exception, throwing the error message in Stack Trace.
==========================================================
java.lang.NullPointerException
at com.evermind.server.ejb.EJBUtils.cloneOneObjectInstance(EJBUtils.java:416)
at com.evermind.server.ejb.EJBUtils.cloneArrayList(EJBUtils.java:599)
at com.evermind.server.ejb.EJBUtils.cloneObject(EJBUtils.java:357)
at ETOperationUtilitiesSession_StatelessSessionBeanWrapper136.getHouseChargesPrefs(ETOperationUtilitiesSession_StatelessSessionBeanWrapper136.java:5965)
at ETAHouseDocumentController.doPost(ETAHouseDocumentController.java:615)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:721)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
at com.evermi[i]Long postings are being truncated to ~1 kB at this time.Hi
The Problem which I posted earlier seems to be like..
If a EJB (Remote) has a method that returns an ArrayList, and one of the entries of the ArrayList is null, we get a NullPointerException, when clonnning the ArrayList .
This looks same as the one posted in relation EJB-Remote returning HashMap has null values. -
Null pointer exception with Lists
Hi,
I have got a problem with java.util.List. It is giving Null pointer exception whenever I try to add after extracting from my XML file.I have written the code like this:
List year; //Global variable
List loaddatas; //Global variable
Element e1; //Global
loaddatas=root.getChild("Load").getChildren("LoadData");
int k=loaddatas.size();
for(int i=0;i<loaddatas.size();i++)
e1=(Element)loaddatas.get(i);
year.add(i,Integer.valueOf(e1.getChildText("Year"))); // I am getting exception here.....
root is root element in XML file.
I am able to display "Integer.valueOf(e1.getChildText("Year"))" correctly.
Anybody please tell me how to solve this.
Thanks,
Sai RamLooks like somebody forgot to learn to program before starting to write code....
List list = new ArrayList(); -
Null Pointer exception returned when object is not null!
I've isolated the problem and cut down the code to the minimum. Why do I get a null pointer exception when the start method is called, when the object objJTextField is not null at this point???? I'm really stuck here, HELP!
(two small java files, save as BasePage.java and ExtendedPage.java and then run ExtendedPage)
first file
~~~~~~~
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public abstract class BasePage extends JFrame implements ActionListener
private JPanel objJPanel = null;
public BasePage()
setSize(300,200);
Container objContentPane = getContentPane();
objJPanel = new JPanel();
createObjects();
createPage();
// Add panels to content pane
objContentPane.add(objJPanel);
public void addComponentToPage(JComponent objJComponent)
objJPanel.add(objJComponent);
public void addButtonToPage(JButton objJButton)
objJButton.addActionListener(this);
objJPanel.add(objJButton);
public void actionPerformed(ActionEvent objActionEvent)
System.out.println("Action performed");
userDefinedButtonClicked(objActionEvent.getActionCommand());
// overide
public abstract void createObjects();
public abstract void createPage();
public abstract void userDefinedButtonClicked(String sActionCommand);
file 2
~~~~
import javax.swing.*;
public class ExtendedPage extends BasePage
private JTextField objJTextField = null;
private JButton objJButtonBrowse = null;
public ExtendedPage()
super();
public void createObjects()
objJTextField = new JTextField(20);
objJButtonBrowse = new JButton("Start");
objJButtonBrowse.setActionCommand("START");
public void createPage()
addComponentToPage(objJTextField);
addButtonToPage(objJButtonBrowse);
public void userDefinedButtonClicked(String sActionCommand)
if ((sActionCommand != null) && (sActionCommand.equals("START")) )
start();
private void start()
objJTextField.setText("Doesn't work");
public static void main(String[] args)
ExtendedPage objEP = new ExtendedPage();
objEP.show();Hello ppaulf,
Your problem is in your ExtendedPage.java file. You can fix this by changing the line
private JTextField objJTextField = null;to:
private JTextField objJTextField = new JTextField();This creates a proper instance.
Good luck,
Ming
Developer Technical Support
http://www.sun.com/developers/support -
Getting java.lang.Null pointer Exception when i close the pdf file.
Hi,
my application is java based thick client application.
From my application, i am generating report file using crystal report tool.
the report file is exported as pdf format and stored in my local macine. from this path, am displaying the report in a SWT browser.
till now its working fine. when i close the browser, i am getting java.lang.null.pointer exception.
i dont understand from this exception, printed in console.
please help me.
java.lang.NullPointerException
at org.eclipse.swt.ole.win32.OleClientSite.onPaint(OleClientSite.java:921)
at org.eclipse.swt.ole.win32.OleClientSite.access$2(OleClientSite.java:906)
at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:131)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1424)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3842)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4541)
at org.eclipse.swt.internal.ole.win32.COM.CoFreeUnusedLibraries(Native Method)
at org.eclipse.swt.ole.win32.OleClientSite.releaseObjectInterfaces(OleClientSite.java:1084)
at org.eclipse.swt.ole.win32.OleControlSite.releaseObjectInterfaces(OleControlSite.java:683)
at org.eclipse.swt.ole.win32.OleClientSite.onDispose(OleClientSite.java:852)
at org.eclipse.swt.ole.win32.OleClientSite.access$1(OleClientSite.java:847)
at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:128)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
at org.eclipse.swt.widgets.Widget.release(Widget.java:804)
at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:755)
at org.eclipse.swt.widgets.Widget.release(Widget.java:807)
at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:755)
at org.eclipse.swt.widgets.Widget.release(Widget.java:807)
at org.eclipse.swt.widgets.Widget.dispose(Widget.java:441)
at com.siemens.med.cad.hqm.reports.ReportViewer$1.widgetDisposed(ReportViewer.java:273)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:117)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
at org.eclipse.swt.widgets.Widget.release(Widget.java:804)
at org.eclipse.swt.widgets.Widget.dispose(Widget.java:441)
at org.eclipse.swt.widgets.Decorations.dispose(Decorations.java:446)
at org.eclipse.swt.widgets.Shell.dispose(Shell.java:674)
at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:308)
at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1643)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3789)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2371)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
at com.siemens.med.cad.hqm.view.mainUI.HQMMainForm.buildMainShell(HQMMainForm.java:246)
at com.siemens.med.cad.hqm.event.UserLoginEventHandler.loginDisplay(UserLoginEventHandler.java:240)
at com.siemens.med.cad.hqm.event.UserLoginEventHandler.widgetSelected(UserLoginEventHandler.java:97)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
this is the code i have written for display the report file in a browser:
Display display = Display.getDefault() ;
Shell shell = new Shell(display, SWT.RESIZE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL);
shell.setText(reportTitle);
shell.setLayout(new FillLayout());
shell.setMaximized(false);
shell.setSize(800, 600);
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new FillLayout());
final Browser browser = new Browser(comp, SWT.FLAT);
try {
File file = new File(exportFile);
URL url = file.toURL();
browser.setUrl("file:" + url.getPath());
} catch (MalformedURLException malURLEx) {
// malURLEx.printStackTrace();
throw new ProgrammingExceptionAdapter(malURLEx);
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
File file = new File(exportFile);
if (file != null && file.exists()) {
file.delete();
browser.dispose();
shell.open();
shell.setFocus()'TitiTruc, welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
I'm locking this thread now.
db -
Xi 3.1 SP3 giving java null pointer exception error on scheduling webi
after we have the system uptime running for a few days and have schedule webi jobs successfully for a few days, we constant get the message java null pointer exception error on scheduling webi.
This only have days after restarting the environment.
Seems to be coming up after scheduling a certain amount of webi reports.
Only doing a stop all services and restart resolves the issue.
XI 3.1 SP3
SAP IK Sp3
Tomcat55
HPUX-IA64 (Hpunix) platform.Hello, I have the same issue. If someone gives you an answer please let me know how to fix it.
-
SAP Portal Display Documents is hanging with Null Pointer Exception
Hi I am having problems with an iview from the products section of SAP standard iviews
In my portal page I have the following three iviews, find documents, display master data and display documents both the find docs and display master data work great, but the display documents seems to hang and a java Null Pointer Exception shows in the data frame of IE. It hangs up the whole page and I have to keep hitting back button to close the window and open. I have the following in config for web front end
DOC_OBJ is mapped to DOKAR, DOKNR, DOKVR and DOKTL with default set.
DOC_REQ is set to DOKAR default checked
EQUI_REQ is set to EQUI-EQUNR default checked
This is under SIMG_SPORT -> products -> select data fields for web front end
Am I missing something?
Cheers,
DevlinThe following code is your problem:
//-------construct
public void MySlide()
contents = new Tile[ROWS][COLS];
reset();
}Constructors don't return anything including void. Therefore you really aren't calling the above method as you assume in your main method as it is not a constructor. Remove the void keyword and your initializing code will execute properly. -
Help with Null Pointer Exception
Hi, I am working on a simple menu program. It compiles and works correctly except for one item. I am having a problem with Greying out a menu item...... Specifically, When I press the EDIT / OPTIONS / READONLY is supposed to Greyout the Save and SaveAs options. But, when I do that it displays a Null Pointer Exception error message in the command window.
Your advice would be much appreciated!
Now for the code
/ FileName Menutest.java
// Sample Menu
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MenuTest extends JFrame {
private Action saveAction;
private Action saveAsAction;
private JCheckBoxMenuItem readOnlyItem;
// set up GUI
public MenuTest()
super( "Menu Test" );
//* file menu and menu items
// set up File menu and its menu items
JMenu fileMenu = new JMenu( "File" );
// set up New menu item
JMenuItem newItem = fileMenu.add(new TestAction( "New" ));
// set up Open menu item
JMenuItem openItem = fileMenu.add(new TestAction( "Open" ));
// add seperator bar
fileMenu.addSeparator();
// set up Save menu item
JMenuItem saveItem = fileMenu.add(new TestAction( "Save" ));
// set up Save As menu item
JMenuItem saveAsItem = fileMenu.add(new TestAction( "Save As" ));
// add seperator bar
fileMenu.addSeparator();
// set up Exit menu item
JMenuItem exitItem = new JMenuItem( "Exit" );
exitItem.setMnemonic( 'x' );
fileMenu.add( exitItem );
exitItem.addActionListener(
new ActionListener() { // anonymous inner class
// terminate application when user clicks exitItem
public void actionPerformed( ActionEvent event )
System.exit( 0 );
} // end anonymous inner class
); // end call to addActionListener
//* Edit menu and menu items
// set up the Edit menu
JMenu editMenu = new JMenu( "Edit" );
//JMenuItem editMenu = new JMenu( "Edit" );
// set up Cut menu item
Action cutAction = new TestAction("Cut");
cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif"));
// set up Copy menu item
Action copyAction = new TestAction("Copy");
copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif") );
// set up Paste menu item
Action pasteAction = new TestAction("Paste");
pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif") );
editMenu.add(cutAction);
editMenu.add(copyAction);
editMenu.add(pasteAction);
// add seperator bar
editMenu.addSeparator();
// set up Options menu, and it submenus and items
JMenu optionsMenu = new JMenu("Options");
readOnlyItem = new JCheckBoxMenuItem("Read-only");
readOnlyItem.addActionListener(
new ActionListener()
{ // anonymous inner class
public void actionPerformed( ActionEvent event)
saveAction.setEnabled(!readOnlyItem.isSelected());
saveAsAction.setEnabled(!readOnlyItem.isSelected());
} // end anonymous inner class
); // end call to addActionListener
optionsMenu.add(readOnlyItem);
// add seperator bar
optionsMenu.addSeparator();
// Work on Radio Buttons
ButtonGroup textGroup = new ButtonGroup();
JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert");
insertItem.setSelected(true);
JRadioButtonMenuItem overTypeItem = new JRadioButtonMenuItem("Overtype");
textGroup.add(insertItem);
textGroup.add(overTypeItem);
optionsMenu.add(insertItem);
optionsMenu.add(overTypeItem);
editMenu.add(optionsMenu);
//* Help menu and menu items
// set up the Help menu
JMenu helpMenu = new JMenu( "Help" );
helpMenu.setMnemonic( 'H' );
// set up index menu item
JMenuItem indexItem = helpMenu.add(new TestAction( "Index" ));
indexItem.setMnemonic( 'I' );
helpMenu.add( indexItem );
// set up About menu item
JMenuItem aboutItem = new JMenuItem( "About" );
aboutItem.setMnemonic( 'A' );
helpMenu.add( aboutItem );
aboutItem.addActionListener(
new ActionListener() { // anonymous inner class
// display message dialog when user selects Open
public void actionPerformed( ActionEvent event )
JOptionPane.showMessageDialog( MenuTest.this,
"This is MenuTest.java \nVersion 1.0 \nMarch 15, 2004",
"About", JOptionPane.PLAIN_MESSAGE );
} // end anonymous inner class
); // end call to addActionListener
// create menu bar and attach it to MenuTest window
JMenuBar bar = new JMenuBar();
setJMenuBar( bar );
bar.add( fileMenu );
bar.add( editMenu );
bar.add( helpMenu );
setSize( 500, 200 );
setVisible( true );
} // end constructor
public static void main( String args[] )
MenuTest application = new MenuTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// inner class to handle action events from menu items
private class ItemHandler implements ActionListener {
// process color and font selections
public void actionPerformed( ActionEvent event )
repaint();
} // end method actionPerformed
} // end class ItemHandler
// Prints to action name to System.out
class TestAction extends AbstractAction
public TestAction(String name) { super(name); }
public void actionPerformed( ActionEvent event )
System.out.println(getValue(Action.NAME) + " selected." );
} // end class TestAction
} // end class MenuTestalan, I've been trying to figure out a solution.
You can initialize it like this
private Action saveAction= new Action();
private Action saveAsAction=new Action();
THE ABOVE WILL NOT WORK.
because Action is an interface. An interface does not have constructors. However, interface references are used for polymorphic purposes.
Anyway, all you have to do is find some class that implemets Action interface.... I cant seem to find one. Or maybe this is not how its supposed to be done?
Hopefully, someone can shed some light on this issue.
FYI,
http://java.sun.com/products/jfc/swingdoc-api-1.1/javax/swing/Action.html -
Use of Bind Variable in the Query of view object giving null pointer excep
I am using this code in the backing bean of my page to set the value of the bind variable 'cmdID' in the view object.
String AM = "model.UnixCommandsAppMod";
String CF = "UnixCommandsAppModLocal";
ApplicationModule am = Configuration.createRootApplicationModule(AM, CF);
ViewObject vo = am.findViewObject("Command_options_view");
vo.setNamedWhereClauseParam("cmdID", 1);
vo.executeQuery();
On the fifth line it is giving NullPointer exception.
I am not being able to figure out the reason.User,
a). Don't keep posting new questions in the same thread. It really does decrease the usability of the forum. Now, if someone searches for "INFO: ADF Faces is running with time-stamp checking enabled," they will find a post about null pointer exception in a bind variable and think, "oh, that doesn't apply to me." If your question is answered, mark the answer as correct. New questions go into a new thread. Kind of funny that the thread I pointed you to with the answer to your question also has this same admonishment.. ;)
b). I'll relent and answer your new question. Ignore that INFO message. It is not an error. It will ALWAYS ALWAYS appear when you run your application in the embedded OC4J with JDeveloper. Had you searched the forum for "INFO: ADF Faces is running with time-stamp checking enabled" you would find that the first hit (among some others) has this same answer
John -
Null pointer exception to database
I can' figure out why it keeps giving me a null pointer exception. I have a database in which I am supposed to search through it based on user input given on a servlet page. Here is the code. Also if anyone could help me on how to execute queries based on an exact search, all search, or any search, that would be great. thanks
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class WelcomeServlet extends HttpServlet{
String keywords = null;
int nResults = 0;
String logic = null;
StringTokenizer list;
int nRows = 0;
int i = 0;
Statement stmt = null;
ResultSet rs = null;
String[] wordList = null;
public void init()
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException cnfe){};
try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/cop4610webs",
"root", "anatoly");
conn.createStatement();
conn.close();
}catch(SQLException sqle){};
protected void doGet(HttpServletRequest req, HttpServletResponse rep) throws IOException
try{
keywords = req.getParameter("keywords");
logic = req.getParameter("logic");
nResults = Integer.parseInt(req.getParameter("number"));
rep.setContentType("text/html");
PrintWriter out = rep.getWriter();
out.println("<html>");
// head section of document
out.println( "<head><title>Servlet Example</title></head>");
// body section of document
out.println( "<body>" );
out.println( "<h1>Welcome to Servlets!</h1>" );
// if(keywords.length()==0)
//out.println("NO SEARCH WORDS WERE ENTERED, PRESS BACK TO ENTER SEARCH WORD(S)");
//else
rs = stmt.executeQuery("SELECT protocolID,serverID,pageName FROM pages WHERE pageContent LIKE %ucf%");
out.println(rs.getString(1) + rs.getString(2) + rs.getString(3));
out.println( "</body>" );
// end XHTML document
out.println( "</html>" );
out.close(); // close stream to complete the page
}catch(SQLException sqle){};
}It's easy to see why:
conn.createStatement();This method returns a Statement, but you don't assign that value to anything. Your data member stmt is set to null and you never change the value.
You've got another problem, though. Once you close that connection you can't talk to the database anymore.
You either have to create a connection inside the doGet and close both as soon as you're done with it OR figure out how to use a connection pool. Tomcat can do it for you. Maybe it's worth a read:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
You're not working with the ResultSet properly, either. Do something like this:
rs = stmt.executeQuery("SELECT protocolID,serverID,pageName FROM pages WHERE pageContent LIKE %ucf%");
while (rs.next())
out.println(rs.getString(1) + rs.getString(2) + rs.getString(3));
}I'm not sure how well that LIKE clause is going to work out.
I'd look at the JDBC tutorial to the left, too. It doesn't look like you've done SQL and JDBC before. - MOD
Maybe you are looking for
-
This is regarding interface from legacy system to SAP
Hi All, We have trasferred the one file from legacy system to SAP, and it was created a session in SM35, it contains 1000 errors. we don't want correct those errors and these entries should be delated, could you please let me know are these errors ca
-
What is the underlying issue? Here are the symptoms...
I have a combination of issues here, and they all seemed to be linked but I cannot wrap my head around it. Here goes: (1) System Preferences freezes when I try to alter trackpad settings (2) Mac Software Updates will not install and cites an "input/
-
Pictures in iPhoto unavailable
When in iPhoto, the thumbnails of some events and pictures keep disapearing. When I try to view these photos, there's an unavailable sign, but the preview on the lower bar still shows. I can't find them in the iPhoto Library. Here's what's happening:
-
Always oats.ear deployement failed in weblogic server
Hi, Iam new to OATS. I am getting the below error in weblogic server when I am trying to open the OTM through browser. Can any one help me? [HTTP:101216]Servlet: "struts-action" failed to preload on startup in Web application: "olt". javax.ejb.EJBExc
-
ok so last night i finally decided to do the upgrade on my phone... well i guess BIG mistake.... now my phone is tripping.... my apps arent working right.... had to delete fb several times..... my photos wouldnt load back up....and my ipod music woul