I am getting Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException while running applet launched via JNLP.  My applet code is  package com.oprs.common;  import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.MalformedURLException; import java.net.URL;  import javax.jnlp.*; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel;  import org.jfree.util.Log; /**  *  * @date Aug 29, 2012 11:33:16 AM  * @version 1.0  */ public class OprsJNLP {      /**      * @param args      */     static BasicService basicService = null;      public static void main(String[] args) {     JFrame frame = new JFrame("OPRS");     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JLabel label = new JLabel();     Container content = frame.getContentPane();     content.add(label,BorderLayout.CENTER);     String message = "Download OPRS Application";     label.setText(message);      try {         basicService = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");     } catch (UnavailableServiceException e) {         Log.error("service not available", e);     }      JButton button = new JButton("http://google.com/");      ActionListener listener = new ActionListener() {          public void actionPerformed(ActionEvent event) {         URL url;         try {             url = new URL(event.getActionCommand());             basicService.showDocument(url);         } catch (MalformedURLException e) {             e.printStackTrace();         }                }     };      button.addActionListener(listener);      content.add(button, BorderLayout.SOUTH);     frame.pack();     frame.show();     } }   I tried to debug and found that basicService is returning null always. In place of google.com i tried with the other url's but still getting the same error. The line basicService.showDocument(url); is where it throws null pointer because my basicService is null. Can some one point out where exactly i am going wrong ?  Including my .jnlp  &lt;?xml version='1.0' encoding='UTF-8' ?&gt; &lt;jnlp spec='1.0'       codebase='http://localhost:9999/'       href='oprs.jnlp'&gt;   &lt;information&gt;     &lt;title&gt;OPRS&lt;/title&gt;     &lt;vendor&gt;OPRS&lt;/vendor&gt;     &lt;description kind='one-line'&gt;       OPRS WEB START     &lt;/description&gt;     &lt;shortcut online='false'&gt;       &lt;desktop/&gt;     &lt;/shortcut&gt;   &lt;/information&gt;   &lt;resources&gt;     &lt;j2se version='1.4+' /&gt;     &lt;jar href='oprs.jar' main='true' /&gt;   &lt;/resources&gt;   &lt;application-desc main-class='com.oprs.OprsJNLP' /&gt; &lt;/jnlp&gt;
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
77222
I have a really simple Java class that effectively decorates a Map with input validation, with the obvious void set() and String get() methods.  I'd like to be able to effectively call those methods and handle return values and exceptions from outside the JVM, but still on the same machine Update: the caller I have in mind is not another JVM; thanks @Dave Ray  My implementation considerations are typical    performance ease of implementation and maintenance (simplicity?) reliability flexibility (i.e. can I call from a remote machine, etc.)   Is there a 'right way?' If not, what are my options, and what are the pro/cons for each?  (Stuff people have actually done and can provide real-life feedback on would be great!)
98616
I can hookup to AppDomain.CurrentDomain.UnhandledException to log exceptions from background threads, but how do I prevent them terminating the runtime?
1271
We have a community built with custom lightning components and the locker service update is active. The onclick event has been defined on several components. The onclicks are working fine in Chrome, Firefox and IE11.   &lt;a href="" onclick="{!c.updateUser}"&gt;Save&lt;/a&gt;   There seem to be some issues in MS Edge though. When we click on an element with an onclick defined, we get the following error:     This page has an error. You might just need to refresh it. Error in $A.getCallback() [Unable to get property 'apply' of undefined or null reference] Failing descriptor: {markup://aura:html}    We have been testing on 5 different laptops. 3 of them have the error, while the other 2 don't have the issue in Edge. This was all tested in a Spring 17 sandbox. We also tested on a Winter 17 org with one of the laptops that has the issue and then everything seems to work fine.  Another test we did, was to remove all of the logic within the controller method and just have a console.log in it, but it never reached that point of the code since we didn't get the log. We also replaced the expression for the onclick with an alert, but that also doesn't work.  Does anyone have an idea how we can resolve this?
119160
This Trigger is on lead (Before Insert, Before Update) and it errors (System.NullPointerException: Attempt to de-reference a null object). I'm getting this error when i'm posting "Web to Lead". However i do have the right ORG iD and Record type id included on the xml file:   &lt;input type=hidden name="oid" value="xxxxxxxxxxxxx"&gt; &lt;input type=hidden name="recordType" id="recordType" value="zzzzzzzzzzzzzzzzzz"&gt;    trigger IAAILeadTrigger on Lead (before insert, before update){ //BEGIN: S-444340 T-561808 - Process only IAA Remarketing Recordtype data     Map&lt;ID,Schema.RecordTypeInfo&gt; rt_Map = Lead.sObjectType.getDescribe().getRecordTypeInfosById();      //Looks up the branches based on the Lead PostalCode     if(trigger.isBefore){          for(Lead ld : trigger.new){                      if (rt_map.get(ld.recordTypeID).getName().containsIgnoreCase('IAA Remarketing') )                if( trigger.isInsert ||                    (trigger.isUpdate &amp;&amp; ld.Branch__c == null) ||                   (trigger.isUpdate &amp;&amp; ld.PostalCode != trigger.oldMap.get(ld.id).PostalCode)               ){                   leads.add(ld);               }           }           }                 //Only check the leads that are in the lead list and NOT the full trigger.new list         if(!leads.isEmpty()){             LeadController.GetLeadBranches(leads);           }     }  }
57448
So, I've been spending considerable more time on SO recently than I normally have, and one thing that I've noticed is quite a few people saying stuff like "There's a Null Pointer Error in this block of code, please help me fix it", with a huge amount of code posted, and no real clue as to where the NPE is. So my question is, what can we do to accomplish 2 goals?   Help the person asking the question become a better programmer. Help them to solve their problems.
2097
I'm getting a NoSuchMethodError error when running my Java program.  What's wrong and how do I fix it?
84069
I am working on selenium. I am using linux os. I am using firefox driver for automated testing my app. My firefox version is 53.0.3 (64 bit). When I run the code the Firefox browser open and don't pass the URL, meanwhile getting an error.   My selenium code:  //Firefox driver      System.setProperty("webdriver.gecko.driver","pathToGeckodriver");     driver =new FirefoxDriver();   Console error:  java.lang.IllegalStateException: The driver executable does not exist: /home/naveen/IdeaProjects/QberTestCase/pathToGeckodriver     at com.google.common.base.Preconditions.checkState(Preconditions.java:199)     at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)     at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)     at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:37)     at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:95)     at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)     at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277)     at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:247)     at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:242)     at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:238)     at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:127)     at util.DriverManager.&lt;init&gt;(DriverManager.java:39)     at steps.LoginSteps.&lt;init&gt;(LoginSteps.java:13)     at user.userTest.initDriver(userTest.java:25)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:498)     at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)     at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)     at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)     at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)     at org.testng.SuiteRunner.privateRun(SuiteRunner.java:307)     at org.testng.SuiteRunner.run(SuiteRunner.java:270)     at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)     at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)     at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)     at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)     at org.testng.TestNG.runSuites(TestNG.java:1124)     at org.testng.TestNG.run(TestNG.java:1096)     at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)     at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127)   Test ignored.
13711
I am trying to install a Java application on my Linux machine (Slackware).   I have received the following error, and I do not understand it.   Could you advise me how to approach the problem? Thank you.  Here is what I get: (I see that some X11 DISPLAY variable needs to be set, but what value should I give it and how?)  ~$ java -jar gate-5.0-beta1-build3048-installer.jar - ERROR -  java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.GraphicsEnvironment.checkHeadless(Graphic sEnvironment.java:159) at java.awt.Window.&lt;init&gt;(Window.java:407) at java.awt.Frame.&lt;init&gt;(Frame.java:402) at net.sourceforge.mlf.metouia.borders.MetouiaDotsBuf fer.&lt;init&gt;(MetouiaDotsBuffer.java:105) at net.sourceforge.mlf.metouia.borders.MetouiaDots.&lt;i nit&gt;(MetouiaDots.java:66) at net.sourceforge.mlf.metouia.borders.MetouiaToolBar Border.&lt;init&gt;(MetouiaToolBarBorder.java:49) at net.sourceforge.mlf.metouia.MetouiaLookAndFeel.ini tComponentDefaults(MetouiaLookAndFeel.java:241) at javax.swing.plaf.basic.BasicLookAndFeel.getDefault s(BasicLookAndFeel.java:130) at javax.swing.plaf.metal.MetalLookAndFeel.getDefault s(MetalLookAndFeel.java:1591) at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:537) at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:581) at com.izforge.izpack.installer.GUIInstaller.loadLook AndFeel(GUIInstaller.java:373) at com.izforge.izpack.installer.GUIInstaller.&lt;init&gt;(G UIInstaller.java:116) at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Construc tor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:30 at com.izforge.izpack.installer.Installer.main(Instal ler.java:62)
785
I am getting a NoClassDefFoundError when I run my Java application.  What is typically the cause of this?
25839
Error Message:     Developer script exception from Nicomatic : quotepotential :   quotepotential: execution of AfterUpdate caused by:   System.DmlException: Update failed. First exception on row 0 with id   a0Q90000005PoxtEAC; first error: UNABLE_TO_LOCK_ROW, unable to obtain   exclusive access to this record: [] Trigger.quotepotential: line 14,   column 1      Apex script unhandled trigger exception by user/organization:   00590000001A6jh/00D90000000bovq      quotepotential: execution of AfterUpdate      caused by: System.DmlException: Update failed. First exception on row   0 with id a0Q90000005PoxtEAC; first error: UNABLE_TO_LOCK_ROW, unable   to obtain exclusive access to this record: []      Trigger.quotepotential: line 14, column 1   these mails are getting to my mail..........  trigger quotepotential on Quote_Line_Item__c (after insert,after update) {     Set&lt;Id&gt; quoteIds = new Set&lt;Id&gt;();     List&lt;Quote__c&gt; quotes = new List&lt;Quote__c&gt;();     for (Quote_Line_Item__c record: Trigger.new) {         if (record.Quote1__c != null){             quoteIds.add(record.Quote1__c);         }     }     for(AggregateResult ar:[                 SELECT                      Quote1__c,                      SUM(Max_Batch__c)sumMax                  FROM Quote_Line_Item__c                  WHERE Quote1__c=:quoteIds                  GROUP BY Quote1__c                 ]) {          quotes.add(new Quote__c(              Id=(Id) ar.get('Quote1__c'),              Potential__c = (Decimal) ar.get('sumMax')              ));     }     if (quotes.isempty() == false) {         update quotes;     } }
107801
I posted the code below to the Sun developers forum since I thought it was erroring (the true error was before this code was even hit).  One of the responses I got said it would not work and to throw it away.  But it is actually working.  It might not be the best code (I am new to Java) but is there something inherently "wrong" with it?   =============  CODE:   private static void ImportFromCsvToAccessTable(String mdbFilePath, String accessTableName  , String csvDirPath , String csvFileName ) throws ClassNotFoundException, SQLException {      Connection msConn = getDestinationConnection(mdbFilePath);     try{          String strSQL = "SELECT * INTO " + accessTableName + " FROM [Text;HDR=YES;DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";         PreparedStatement selectPrepSt = msConn.prepareStatement(strSQL );         boolean result = selectPrepSt.execute();                 System.out.println( "result = " + result );      } catch(Exception e) {         System.out.println(e);     } finally {         msConn.close();     } }
104804
I've been keep on getting NoSuchElementException whenever I try to get an web element. I know that the web element becomes present after some time. So, I've explicitly waited for 5-10 seconds until the web element gets loaded but even then I am still getting NoSuchElementException. Does anyone know how to prevent this exception? Here is my code:  String s=System.getProperty("user.dir"); System.setProperty("webdriver.chrome.driver", s+"\\Chrome090615\\chromedriver.exe"); ChromeDriver driver=new ChromeDriver(); try{     driver.manage().window().maximize();     driver.get("http://site21.way2sms.com/content/index.html");      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);     driver.findElementByXPath("//*[@id='username']").sendKeys("9XXXXXXXXX");     driver.findElementByXPath("//*[@id='password']").sendKeys("XXXX");     driver.findElementByXPath("//*[@id='loginBTN']").click();     if(driver.findElementByXPath("//*[@id='ebFrm']/div[2]/div[1]/input").isDisplayed()==true)     {         driver.findElementByXPath("//*[@id='ebFrm']/div[2]/div[1]/input").click();     }     else {         new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.id("ebFrm")));         System.out.println("Waiting for 5 secs");     }     boolean ispresent=driver.findElementByXPath("//*[@id='sendSMS']/a").isDisplayed();     driver.findElementByXPath("//*[@id='sendSMS']/a").click();     System.out.println("Clicked sendSms");     driver.findElementByXPath("//*[@id='sendSMS']/a").click();   I'm getting exception for the 'sendSMS' id. Whenever it tries to find this element, it throws NoSuchElementException all the time!
61954
Note I'm running windows, the path just looks like it's linus because I typed it manually and thats how I think of paths.  I'm trying to run a java class That I have built to diagnose my connection to a databse, it references the oracle jdbc adaptor.  When I just run it without a class path:  %&gt; java DBDiagnostics &lt;connectionString&gt;   I get an exception when it reaches the following line of code:  Class.forName("oracle.jdbc.pool.OracleDataSource").newInstance();   with the following exception:  java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)         at java.lang.Class.forName0(Native Method)         at java.lang.Class.forName(Class.java:169)         at DBDiagnostics.GetConnection(DBDiagnostics.java:43)         at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29)         at DBDiagnostics.main(DBDiagnostics.java:18) Creating connection. java.sql.SQLException: No suitable driver found for lskd         at java.sql.DriverManager.getConnection(DriverManager.java:602)         at java.sql.DriverManager.getConnection(DriverManager.java:207)         at DBDiagnostics.GetConnection(DBDiagnostics.java:55)         at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29)         at DBDiagnostics.main(DBDiagnostics.java:18) Veryfying connectivity to Database Exception in thread "main" java.lang.NullPointerException         at DBDiagnostics.verifyTable(DBDiagnostics.java:86)         at DBDiagnostics.verifyTable(DBDiagnostics.java:76)         at DBDiagnostics.verifyDatabseConnectivity(DBDiagnostics.java:68)         at DBDiagnostics.runDiagnostic(DBDiagnostics.java:36)         at DBDiagnostics.main(DBDiagnostics.java:18)   I assume that this is because I need to include it in the classpath.   So, I tried adding it to the classpath like this:  %&gt; java -classpath .:ojdbc6.jar DBDiagnostics &lt;connectionString&gt;   The VM just says it cant find the class:   Exception in thread "main" java.lang.NoClassDefFoundError: DBDiagnostics Caused by: java.lang.ClassNotFoundException: DBDiagnostics         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Could not find the main class: DBDiagnostics.  Program will exit.   I know this is a question I should just know the answer to, but what am I doing wrong?
120972
My application has javascript button that call Apex code.  Exceptions from web services are sometimes thrown and the user is shown a detailed exception message like this:  A problem with the OnClick JavaScript for this button or link was encountered: {faultcode:'soapenv:Client', faultstring:'HttpException: Example Error Message Class.BananaWebService.fetchBanana: line 22, column 1', }   Is there a simple way to create friendly error messages for my users when exceptions are thrown like this:  Example Error Message   Exception Class  public class HttpException extends Exception{}   Web Service Class   @RestResource(urlMapping='/BananaWebService/*') global class BananaWebService {   webservice static void fetchBanana(Id accountId) {      throw new HttpException('Example Error Message');   } }   Javascript code   {!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}  {!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}   var accountId = "{!Account.Id}"; sforce.apex.execute("BananaWebService","fetchBanana", { accountId: accountId });  window.location.reload();
121649
I am unable to pass parameter from the lightning controller to the apex class. Whenever I use debug the passed value seems null.  JavaScript Controller  add : function(cmp,event,helper) {      event.target.parentNode.style.display = 'none';     document.getElementById("cartdiv").style.display = 'block';     var selectedAccount =event.target.id;      var act = cmp.get("c.Cartveg");     act.setParams({"s":selectedAccount});     act.setParams({"cartlist" : cmp.get("v.cart")});     act.setCallback(this,function(a){         cmp.set("v.cartitem",a.getReturnValue());     });            $A.enqueueAction(act);     cmp.set("v.whichButton", selectedAccount); }   Apex Class  @AuraEnabled public static List&lt;Vegetable__c&gt; Cartveg(string s,List&lt;Vegetable__c&gt; cartlist) {       system.debug(s);   List&lt;Vegetable__c&gt;  clist= [SELECT Id, Name , Price__c , img__c                                  FROM Vegetable__c where Name =:s];      clist.addAll(cartlist);      system.debug(clist);     return clist; }   Value of s is null. Please help
93419
I am using Structure map like the MVC storefront by Rob Conery does and I have an AdminController and so to get to it I just type:  website/Admin/action   however if I miss spell the controller name I get the error below:  Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: key  There error occurs on this line:  Controller controller = ObjectFactory.GetInstance(controllerType) as Controller;   Does anyone have any ideas on how I can handle this error or not allow it to happen at all and maybe just goto a 404 page??  Cheers in advance