Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Re: NullPointerException on getText()
Re: NullPointerException on getText() [message #324956] Mon, 04 February 2008 14:09 Go to next message
Eclipse UserFriend
victorious wrote:
> I'm getting a null pointer exception on a Text when i call the method
> getText() on it. As far as i can see i have instantiated the Text object
> but it still returns a null pointer exception.
>
> If anyone could help it would be great
> Here's the code, followed by the exception
> The exception occurs in the method at the bottom of the code
> createIngredient when i call nameText.getText();
>
>
>
> package com.orderingsystem.desktop.gui.view;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Text;
> import org.eclipse.ui.forms.events.ExpansionEvent;
> import org.eclipse.ui.forms.events.IExpansionListener;
> import org.eclipse.ui.forms.widgets.FormToolkit;
> import org.eclipse.ui.forms.widgets.ScrolledForm;
> import org.eclipse.ui.forms.widgets.TableWrapData;
> import org.eclipse.ui.forms.widgets.TableWrapLayout;
> import org.eclipse.ui.part.ViewPart;
> public class IngredientView extends ViewPart implements IExpansionListener
> {
>
> private FormToolkit toolkit;
> private ScrolledForm form;
>
> private Label nameLabel;
> private Label costLabel;
> private Label idLabel;
> private Label noteLabel;
> private Label supplierLabel;
>
> private Text nameText;
> private Text costText;
> private Text idText;
> private Text supplierText;
>
>
> private static final String validCostString = "0123456789.";
>
> public static final String ID =
> "com.orderingsystem.desktop.gui.ingredientview";
>
> private char[] validCostArray;
>
> public IngredientView()
> {
> validCostArray = validCostString.toCharArray();
> }
> public void createPartControl(Composite parent) {
> toolkit = new FormToolkit(parent.getDisplay());
> form = toolkit.createScrolledForm(parent);
>
> toolkit.decorateFormHeading(form.getForm());
> form.setText("Ingredient");
>
> TableWrapLayout layout = new TableWrapLayout();
> form.getBody().setLayout(layout);
> layout.numColumns =2 ;
> layout.rightMargin = 200;
>
> TableWrapData td = new TableWrapData();
> td.colspan=1;
>
> GridData data = new GridData(SWT.FILL);
>
> td = new TableWrapData(TableWrapData.FILL_GRAB);
>
> nameLabel = toolkit.createLabel(form.getBody(),"Ingredient Name");
>
> nameText = toolkit.createText(form.getBody(), "");
> nameText.setLayoutData(td);
> nameText.setTextLimit(50);
>
> td = new TableWrapData(TableWrapData.FILL);
> idLabel = toolkit.createLabel(form.getBody(),"Ingredient ID");
>
> idText = toolkit.createText(form.getBody(), "");
> idText.setLayoutData(td);
> idText.setTextLimit(10);
>
> td = new TableWrapData(TableWrapData.FILL);
> costLabel = toolkit.createLabel(form.getBody(),"Cost (?)");
>
> costText = toolkit.createText(form.getBody(), "");
> costText.setLayoutData(td);
> costText.setTextLimit(10);
>
> }
>
> public void setFocus() {
> }
>
> public void expansionStateChanging(ExpansionEvent e) {
> }
>
> public void expansionStateChanged(ExpansionEvent e) {
> form.redraw();
> }
>
> public void createIngredient()
> {
> String cost="0.00";
> try {
> String name = nameText.getText();
> String id = idText.getText();
> cost = costText.getText();
> } catch (RuntimeException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> Double.parseDouble(cost);
> }
> }
>
> //---------------------------------------------------------- ----
>
> java.lang.NullPointerException
> at
> com.orderingsystem.desktop.gui.view.IngredientView.createIng redient(IngredientView.java:99)
>
> at
> com.orderingsystem.desktop.gui.ApplicationActionBarAdvisor.g etIngredient(ApplicationActionBarAdvisor.java:150)
>
> at com.orderingsystem.desktop.action.SaveAction.run(SaveAction. java:54)
> at org.eclipse.jface.action.Action.runWithEvent(Action.java:498 )
> at
> org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:546)
>
> at
> org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:490)
>
> at
> org.eclipse.jface.action.ActionContributionItem$6.handleEven t(ActionContributionItem.java:443)
>
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 19)
> at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:289)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:461)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at
> com.orderingsystem.desktop.gui.Application.start(Application .java:20)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:169)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
>
> 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 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 508)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1148)
>
>

Redirecting to eclipse.platform.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Re: NullPointerException on getText() [message #324958 is a reply to message #324956] Mon, 04 February 2008 14:16 Go to previous message
Eclipse UserFriend
Paul Webster wrote:
>>
>> public void createIngredient()
>> {
>> String cost="0.00";
>> try {
>> String name = nameText.getText();
>> String id = idText.getText();
>> cost = costText.getText();
>> } catch (RuntimeException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> Double.parseDouble(cost);
>> }
>> }
>>
>> //---------------------------------------------------------- ----
>>
>> java.lang.NullPointerException
>> at
>> com.orderingsystem.desktop.gui.view.IngredientView.createIng redient(IngredientView.java:99)
>>
>> at
>> com.orderingsystem.desktop.gui.ApplicationActionBarAdvisor.g etIngredient(ApplicationActionBarAdvisor.java:150)
>>
>> at
>> com.orderingsystem.desktop.action.SaveAction.run(SaveAction. java:54)


Where is your ApplicationActionBarAdvisor getting your view part from?
What does the code look like that retrieves your viewpart?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Previous Topic:How to reuse "MarkerView"
Next Topic:editors close -- how to reclaim space for views?
Goto Forum:
  


Current Time: Wed Jul 16 12:57:26 EDT 2025

Powered by FUDForum. Page generated in 0.28340 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top