having trouble with java.lang.NullPointerException error, please help me - oop

enter code hereI have a private boolean exist=false;, this is a local variable of my payrool class
I also have a method searchRecord(int payrollPeriod, int empNo)
public void searchRecord(int payrollPeriod, int empNo)
{
for(int x=0;x<100;x++)
{
if(trans[x].getPayrollPeriod() == payrollPeriod && trans[x].getEmpNo() == empNo)
{
payrollCounter=x;
exist=true;
break;
}
}
}
My array trans[] is a Transaction type (I used composition) consist of record which has payrollPeriod and empNo.
My program runs fine whenever files exist, but when the search is resulted to false java.lang.NullPointerException happens...
please help me, what should I do
ERROR:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at payroll.Payroll.searchRecord(Payroll.java:350)
at payroll.Payroll.actionPerformed(Payroll.java:184)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
TRANSACTION CLASS:
package payroll;
public class Transaction extends Employee
{
//local variable
private int payrollPeriod;
private double hoursWorked;
//constructor
public Transaction(int payrollPeriod, int empNo, String name, String department, double payRate, double hoursWorked)
{
super(empNo, name, department, payRate);
this.payrollPeriod=payrollPeriod;
this.hoursWorked=hoursWorked;
}
//methods
public int getPayrollPeriod()
{
return payrollPeriod;
}
public double getHoursWorked()
{
return hoursWorked;
}
}

The array trans[x] contains null values.
You should either:
Not allow null values in the array when building it.
Check for null values in the loop and skip/handle them.
public void searchRecord(int payrollPeriod, int empNo) {
for(int x = 0; x < trans.length; x++) {
if (trans[x] == null) {
System.out.println("Skipped null value in trans[x]");
continue;
}
if (trans[x].getPayrollPeriod() == payrollPeriod && trans[x].getEmpNo() == empNo) {
payrollCounter = x;
exist = true;
break;
}
}
}

Related

How to add keyListener to the ViewPart

I try to add possibility to close view on ESC button. I have a view NewsContentView and try to add key listener to it by this way
this.addListenerObject(new KeyListener() {
#Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
#Override
public void keyPressed(KeyEvent e) {
if(e.keyCode == SWT.ESC){
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
activePage.hideView(activePage.findView(ID));
}
}
});
but get the error
java.lang.ClassCastException: com.forexgame.ui.views.NewsContentView$1 cannot be cast to org.eclipse.ui.IPropertyListener
at org.eclipse.ui.part.WorkbenchPart.firePropertyChange(WorkbenchPart.java:127)
at org.eclipse.ui.part.WorkbenchPart.internalSetPartName(WorkbenchPart.java:466)
at org.eclipse.ui.part.WorkbenchPart.setPartName(WorkbenchPart.java:384)
at org.eclipse.ui.part.ViewPart.setPartName(ViewPart.java:129)
at com.forexgame.ui.views.NewsContentView.setName(NewsContentView.java:88)
at com.forexgame.ui.views.NewsView.showNewsContentView(NewsView.java:133)
at com.forexgame.ui.views.NewsView.access$0(NewsView.java:121)
at com.forexgame.ui.views.NewsView$1.doubleClick(NewsView.java:92)
at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:832)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:829)
at org.eclipse.jface.viewers.StructuredViewer.handleDoubleSelect(StructuredViewer.java:1150)
at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1263)
at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:252)
at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:249)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:311)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at com.forexgame.application.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
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:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Also I looked for opportunity to add Key Listener to the active page, but IWorkBenchPage interface have no such methods and has only methods
activePage.addPartListener(IPartListener listener);
activePage.addPartListener(IPartListener2 listener);
activePage.addPostSelectionListener(ISelectionListener listener);
activePage.addPostSelectionListener(String partId, ISelectionListener listener);
activePage.addSelectionListener(ISelectionListener listener);
activePage.addSelectionListener(String partId, ISelectionListener listener);
activePage.addPropertyChangeListener(IPropertyChangeListener listener);
Why this error is occurs and whether there is a diffent way to add key listener on a view?

Exception while taking screenshot null and FAILED CONFIGURATION: #AfterMethod teardown

I am facing some trouble and got stuck since yesterday; unable to figure out the cause for it. Tried solution of answers here.
I created #Test, with sample of code to login and check dashaboard of application.
and #AfterMethod, for when Assert is false, should capture a screenshot.
If i comment the Aftermethod code it works fine without any issue;
It used to run fine w/o any problem earlier.
Could you please help me in finding some solution. (it may be very small thing for you.. but pls do help me)
(EDITED) Error i am getting is
[TestNG] Running:
C:\Users\Lenovo\AppData\Local\Temp\testng-eclipse--1410131027\testng-customsuite.xml
Exception while taking screenshot null
FAILED CONFIGURATION: #AfterMethod teardown([TestResult name=dashboardSanityTest status=FAILURE method=loginMain.dashboardSanityTest()[pri:0, instance:demotest.loginMain#1bce4f0a] output={null}])
java.lang.NullPointerException
at demotest.loginMain.teardown(loginMain.java:144)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:703)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
SKIPPED CONFIGURATION: #AfterMethod teardown
FAILED: dashboardSanityTest
java.lang.NullPointerException
at demotest.loginMain.dashboardSanityTest(loginMain.java:105)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
#AfterMethod Code
#AfterMethod
public void teardown(ITestResult result)
{
if (result.getStatus()==ITestResult.FAILURE)
{
String screenshotPath = Utils.captureScreenshot(driver, result.getName());
String image = logger.addScreenCapture(screenshotPath);
}
report.flush();
}
Utils class
public class Utils {
public static String captureScreenshot(WebDriver driver, String ScreenshotName)
{
try
{
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest="./screenshot/"+ScreenshotName+".png";
File snapshotDest =new File(dest);
FileUtils.copyFile(source, snapshotDest);
System.out.println("Screenshot Taken at "+System.currentTimeMillis());
return dest;
}
catch (Exception e)
{
System.out.println("Exception while taking screenshot "+e.getMessage());
return e.getMessage();
}
}
}
Since you have not mentioned complete error stacktrace, it is a bit difficult to identify exact cause of failure. Please check whether driver value is getting null.
I would suggest you to leverage ITestListener instead of using method with #AfterMethod. You simply need to implement ITestListenerwhich will take the screenshot for you on test failure.
public class Listener implements ITestListener {
public WebDriver driver;
#Override
public void onStart(ITestContext arg0) {
Reporter.log("About to begin executing Test " + arg0.getName(), true);
}
#Override
public void onFinish(ITestContext arg0) {
Reporter.log("Completed executing test " + arg0.getName(), true);
}
#Override
public void onTestFailure(ITestResult arg0) {
try {
String fileName = String.format("Screenshot-%s.jpg", Calendar
.getInstance().getTimeInMillis());
driver = (WebDriver) arg0.getTestContext().getAttribute("WebDriver");
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest="./screenshot/"+ fileName;
File snapshotDest =new File(dest);
FileUtils.copyFile(source, snapshotDest);
Reporter.log("Screen Shots file : " + dest);
} catch (Exception e) {
throw new RuntimeException("Failed to take screenshot !", e);
}
}
}
Thanks !

Null pointer when try to make a screenshot in testNG Selenium

When I try to do screen shots I get following error:
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.NullPointerException
at com.volvo.prompt.uitests.selenium.util.ScreenshotOnFailureListener.onConfigurationFailure(ScreenshotOnFailureListener.java:51)
at org.testng.internal.Invoker.runConfigurationListeners(Invoker.java:1868)
at org.testng.internal.Invoker.handleConfigurationFailure(Invoker.java:334)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:237)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:101)
... 9 more
Here is the code: (51st line cause problems)
public class ScreenshotOnFailureListener extends TestListenerAdapter {
#Override
public void onTestFailure(ITestResult tr) {
File screenshotFile = ((TakesScreenshot)TestBase.driver).getScreenshotAs(OutputType.FILE);
String fileName = DateFormatter.getTimestamp(Calendar.getInstance()) + "."
+ System.getProperty("browser") + "."
+ tr.getMethod().getMethodName()
+ ".png";
String path = System.getProperty("webdriver.screenshots");
File targetFile = new File(path + "/" + fileName);
if ( !targetFile.getParentFile().exists() ) {
targetFile.getParentFile().mkdirs();
}
try {
FileUtils.copyFile(screenshotFile, targetFile);
} catch (IOException e) {
e.printStackTrace();
}
Reporter.log("Failed Screenshot");
}
Tests are run from Jenkins. Locally it works :/
Browser used: Chrome.
Thank You for replay in advance
BR
Jakub

time out error in selenium

This is the code I am trying to run
package com.memoir.client.widgets.memogen;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.DefaultSelenium;
#SuppressWarnings("deprecation")
public class TestHomepage extends SeleneseTestCase {
#Override
#Before
public void setUp() throws Exception {
//selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://64.79.128.233/staging/");
selenium = new DefaultSelenium("localhost", 4444, "*firefox /usr/bin/firefox", "https://64.79.128.233/staging/");
selenium.start();
}
#Test
public void testTesting4() throws Exception {
selenium.setSpeed("2000");
selenium.windowMaximize();
//selenium.open("/memosyn/");
selenium.open("/staging/");
selenium.waitForPageToLoad("60000");
//Checking for page layout in the beginning of the web page
assertEquals("1", selenium.getElementIndex("//*[#id='isc_G']"));
assertEquals("Please contact support#systems.com for questions or comments.", selenium.getText("id=contactText"));
//assertEquals("MemoWeb V3.3.5963M", selenium.getText("//*[#id='isc_WidgetCanvas_1_widget']/div/table/tbody/tr/td[2]"));
assertEquals("14", selenium.getElementHeight("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("447", selenium.getElementWidth("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("203", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("22", selenium.getElementHeight("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("100", selenium.getElementWidth("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("MemoWeb", selenium.getTitle());
assertEquals("Email :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email||title=Email]/title"));
assertEquals("Password :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password||title=Password]/title"));
assertEquals("Remember me on this computer", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe||title=Remember%20me%20on%20this%20computer]/textbox"));
}
#Override
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
I get the following error
com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:369)
at com.memoir.client.widgets.memogen.testlayout.testTesting4(testlayout.java:23)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Why does it time out at 30000ms even when I request for 60000ms with waitForPageToLoad?
You are setting the waitForPageToLoad() after open(), and therefore it uses 30000.
Change the order, and try again..
selenium.waitForPageToLoad("60000");
selenium.open("/staging/");

WizardDialog.open() throw NullPointerException

I am trying to add NewCSSWizard on the toolbar. For this I used Platform Command Framework, add command and handler extension points. extends WizardHandler but it doesn't work and throws NPE. If in method executeHandler(ExecutionEvent) I create own wizard - it works well.
public class NewCssWizardHandler extends WizardHandler
{
#Override
protected void executeHandler(ExecutionEvent event)
{
try
{
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
WizardDialog wizardDialog = new WizardDialog(window.getShell(), new NewCSSWizard());
wizardDialog.open();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
}
#Override
protected String getWizardIdParameterId()
{
return IWorkbenchCommandConstants.FILE_NEW_PARM_WIZARDID;
}
#Override
protected IWizardRegistry getWizardRegistry()
{
return PlatformUI.getWorkbench().getNewWizardRegistry();
}
}
Stacktrace:
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.NullPointerException
at org.eclipse.ui.ide.IDE.computeSelectedResources(IDE.java:1480)
at org.eclipse.wst.css.ui.internal.wizard.NewCSSWizard.addPages(NewCSSWizard.java:48)
at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:605)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.sdad.sdk.ui.actions.NewCssWizardHandler.executeHandler(NewCssWizardHandler.java:27)
at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:279)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
Looks like you passed a null argument to computeSelectedResources. Just do a null check before calling that method. I'm assuming that the code you are working on is NewCSSWizard.java.
public class NewFileHandler extends AbstractHandler implements IHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
System.out.println("window ok");
NewFileWizard nfw = new NewFileWizard();
nfw.init(PlatformUI.getWorkbench(), new StructuredSelection());
WizardDialog dialog = new WizardDialog(window.getShell(), nfw);
System.out.println("new WizardDialog");
dialog.open();
System.out.println("dialog open");
return null;
}
}