I have one properties file, name is XYZ.properties. I want to get details from this file. My property file location is D:\properties_file\XYZ.properties  For this i am using below code  import java.io.InputStream; import java.util.Properties;  public class LoadProp {     private static Properties prop = new Properties();     public static Properties getProperties() throws Exception {         if (prop.isEmpty()) {             InputStream fis = LoadProp.class.getResourceAsStream("D:\\properties_file\\XYZ.properties");             prop.load(fis);         }         return prop;     } }  public class demo extends HttpServlet {     private static final long serialVersionUID = 1L;     private static Properties propFile;      public void doPost(HttpServletRequest request, HttpServletResponse response) {         try {             propFile = LoadProp.getProperties();             System.out.println(propFile.getProperty(Constants.URL));         }         catch (ServletException e) {             e.printStackTrace();         } catch (IOException e) {             e.printStackTrace();         } catch (Exception e1) {             e1.printStackTrace();         }     } }   But when i run this on prop.load(fis) line it gives me the following error  java.lang.NullPointerException
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?
8442
I have a file (called "number.txt") which I want to read to an array in Java. How exactly do I go ahead and do this? It is a straight-forward "1-dimensional" file, containing 100 numbers.  The problem is that I get an exception every time. Apparently it can't find it (I am sure its spelled correctly). When looking through code examples, it doesn't specify the file's entire file path, only the name of the file itself. How would I go about doing that if its necessary?  Also, when reading the file, will the array automatically contain all the lines of the file, or will I have to make a loop which which copies every line to corresponding subscript i?  I've heard of BufferedReader class, what it's purpose, and how does it corelate to reading input?
88076
This is what I've come up with as a method on a class inherited by many of my other classes. The idea is that it allows the simple comparison between properties of Objects of the same Type.  Now, this does work - but in the interest of improving the quality of my code I thought I'd throw it out for scrutiny. How can it be better/more efficient/etc.?  /// &lt;summary&gt; /// Compare property values (as strings) /// &lt;/summary&gt; /// &lt;param name="obj"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public bool PropertiesEqual(object comparisonObject) {      Type sourceType = this.GetType();     Type destinationType = comparisonObject.GetType();      if (sourceType == destinationType)     {         PropertyInfo[] sourceProperties = sourceType.GetProperties();         foreach (PropertyInfo pi in sourceProperties)         {             if ((sourceType.GetProperty(pi.Name).GetValue(this, null) == null &amp;&amp; destinationType.GetProperty(pi.Name).GetValue(comparisonObject, null) == null))             {                 // if both are null, don't try to compare  (throws exception)             }             else if (!(sourceType.GetProperty(pi.Name).GetValue(this, null).ToString() == destinationType.GetProperty(pi.Name).GetValue(comparisonObject, null).ToString()))             {                 // only need one property to be different to fail Equals.                 return false;             }         }     }     else     {         throw new ArgumentException("Comparison object must be of the same type.","comparisonObject");     }      return true; }
120287
Why am I getting the following error?  Unknown property   Controller Extension  public class CrewWorkDetailController{      public final Installation__c installation ;      public CrewWorkDetailController(ApexPages.StandardController stdController)     {         this.installation = (Installation__c) stdController.getRecord() ;     } }   View:  &lt;apex:page standardController="Installation__c" extensions="CrewWorkDetailController"&gt;     {!installation.Name} &lt;/apex:page&gt;
38112
Here's the scenario...    if (entry.Properties["something"].Value != null)   attribs.something = entry.Properties["something"].Value.ToString();   While effective and working correctly, this looks ugly to me.  If I don't check for a null before performing the ToString() then it throws an exception if the property was null.  Is there a better way to handle this scenario?  Much appreciated!
14731
It is much more convenient and cleaner to use a single statement like  import java.awt.*;   than to import a bunch of individual classes  import java.awt.Panel; import java.awt.Graphics; import java.awt.Canvas; ...   What is wrong with using a wildcard in the import statement?
2769
I need to store additional information in a .blend file, that occurs only once per file. So, attaching it to, for example, bpy.types.Scene doesn't help.  Since bpy.data is an instance of bpy.types.BlendData, I tried attaching properties to bpy.types.BlendData. This failed:  &gt;&gt;&gt; bpy.types.BlendData.testProp = bpy.props.StringProperty() &gt;&gt;&gt; bpy.data.testProp (&lt;built-in function StringProperty&gt;, {})   Here, bpy.data.testProp is not a string, but some tuple, So it looks like registering properties on bpy.types.BlendData is not supported, like it is for bpy.types.Object:  &gt;&gt;&gt; bpy.types.Object.testProp = bpy.props.StringProperty() &gt;&gt;&gt; bpy.data.objects['Camera'].testProp ''   Is it somehow possible to attach properties to bpy.types.BlendData?  Are there other ways to register global data in a .blend file?
38862
In my application I load resources in this manner:  WinProcessor.class.getResource("repository").toString();   and this gives me:  file:/root/app/repository   (and I replace "file:" with empty string)   This works fine when I run my application from the IDE, but when I run the jar of my application:  java -jar app.jar   The path becomes:  jar:/root/app.jar!/repository   is there any way to solve this problem?  I'll use the "repository" dir name in order to create this:  ConfigurationContext ctx = (ConfigurationContext) ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryString, null);   In the same manner, I'll get one file name (instead of a dir) and I'll use it this way:  System.setProperty("javax.net.ssl.trustStore", fileNameString)
84091
ok, ive a class and i pass an object as property.  the object that i pass is a List&lt;X&gt;  in my class im trying to access the Object index by reflection BUT I CAN'T!!!   Example:  this class works i just wrote down the part i want to show you and i need help.  class MyClass {     private object _recordSet;     public object RecordSet     {         get { return _recordSet; }         set { _recordSet = value; }     }      public string Draw()     {         system.reflection.Assembly asem = system.reflection.Assembly.getAssembly(_dataSource.GetType());          object instance;          instance = asem.CreateInstance(_dataSource.GetType().UnderlyingSystemType.FullName);          //to access de Count of my List         int recordcount = int.Parse(_dataSource.GetType().GetProperty("Count").GetValue(_dataSource,null));          //i need to do a          for(int cont = 0; cont &lt; recordCount; cont++)         {             _dataSource[cont].Name; // &lt;-- THIS PART IS NOT WORKING!!! because i cant access the Index Directly.... WHAT TO DO!! ???         }     } }
61126
I am getting java.lang.NullPointerException while executing my test case , I am using Page Object Modle with PageFactory ,following are the code snippets  LoginPageObjec.java  public class LoginPageObjects {      @FindBy(xpath=".//*[@id='userName']")     private WebElement email;      @FindBy(xpath=".//*[@id='password']")     private WebElement password;      @FindBy(xpath=".//*[@id='loginFormSubmit']")     private WebElement loginBtn;      public void EnterUserName(String userName)     {         email.sendKeys(userName);     }      public void EnterPassword(String pass)     {         password.sendKeys(pass);     }      public void clickLogin()     {         loginBtn.click();     }   }   LoginTC.java  public class LoginTC extends BasePage{     private WebDriver driver;      @Test     public void login()     {         LoginPageObjects loginPage = PageFactory.initElements(driver, LoginPageObjects.class);         loginPage.EnterUserName("test.hr@domin.com.pk");         loginPage.EnterPassword("test");         loginPage.clickLogin();     } public void login1()         {             LoginPageObjects loginPage = PageFactory.initElements(driver, LoginPageObjects.class);             loginPage.EnterUserName("test.hr@domin.com.pk");             loginPage.EnterPassword("test");             loginPage.clickLogin();         }  }   BasePage.java  public class BasePage {     private WebDriver driver;      @BeforeMethod       public void initializeBrowser() {      driver=new FirefoxDriver();      driver.navigate().to("https://nexthrm-dev.vteamslabs.com/");      driver.manage().window().maximize();      }     @AfterMethod     public void closeBrowser()     {         driver.close();     }  }   I've extended BasePage class to utilize the (initialBrowser &amp; closeBrowser) functions in my test case but its producing nullpointer exception if I copy both of the functions (initialBrowser &amp; closeBrowser) into my LoginTC (testcase class) it works like charm but I dont want this redundant code i.e((initialBrowser &amp; closeBrowser) for all my testcases class could anyone explain why I am getting nullpointer exception
30205
I want to check for empty arrays. Google gave me varied solutions but nothing worked. Maybe I am not applying them correctly.  Function GetBoiler(ByVal sFile As String) As String 'Email Signature     Dim fso As Object     Dim ts As Object     Set fso = CreateObject("Scripting.FileSystemObject")     Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)     GetBoiler = ts.ReadAll     ts.Close End Function  Dim FileNamesList As Variant, i As Integer ' activate the desired startfolder for the filesearch FileNamesList = CreateFileList("*.*", False) ' Returns File names ' performs the filesearch, includes any subfolders ' present the result ' If there are Signatures then populate SigString Range("A:A").ClearContents For i = 1 To UBound(FileNamesList)     Cells(i + 1, 1).Formula = FileNamesList(i) Next i  SigString = FileNamesList(3)  If Dir(SigString) &lt;&gt; "" Then     Signature = GetBoiler(SigString) Else     Signature = "" End If   Here if FileNamesList array is empty, GetBoiler(SigString) should not get called at all. When FileNamesList array is empty, SigString is also empty and this calls GetBoiler() function with empty string. I get an error at line   Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)   since sFile is empty. Any way to avoid that?
55087
i am building a app which takes input from user and then search to a remote database(MySql).And then display the retrieved data on VisualForce page.One important note that my app will be distributable.  here is my controller class  public with sharing class Search  {    public String strTag {get;set;}   public String strlocation {get;set;}    public PageReference find() {              return null;   } }   Thanks in advance.  Updated  public with sharing class Search  {   public String strTag {get;set;} public String strlocation {get;set;}   public PageReference find() {             HttpRequest req = new HttpRequest();   HttpResponse res = new HttpResponse();   Http http = new Http();    req.setEndpoint('https://localhost/salesforce/');   req.setMethod('POST');     req.setCompressed(false);   req.setBody('key1=value1&amp;key2=value2');   req.setHeader('Content-Type', 'application/x-www-form-urlencoded');      try {     res = http.send(req);   } catch(System.CalloutException e) {     system.debug('Callout error: '+ e);   }   system.debug(res.getBody());      return null;  } }   I am getting below error now      error message System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = localhost/salesforce
77755
&lt;servlet&gt;     &lt;servlet-name&gt;myservlet&lt;/servlet-name&gt;     &lt;servlet-class&gt;workflow.WDispatcher&lt;/servlet-class&gt;     &lt;load-on-startup&gt;2&lt;/load-on-startup&gt; &lt;/servlet&gt;  &lt;servlet-mapping&gt;     &lt;servlet-name&gt;myservlet&lt;/servlet-name&gt;     &lt;url-pattern&gt;*NEXTEVENT*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt;   Above is the snippet from Tomcat's web.xml. The URL pattern *NEXTEVENT* on start up throws     java.lang.IllegalArgumentException: Invalid &lt;url-pattern> in servlet mapping   It will be greatly appreciated if someone can hint at the error. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
93772
below is my code Created a wrapper class like below  public class ResponseWrapper{     public list&lt;Account&gt; lstaccounts;     public boolean isError ;     public string errorCode;     public integer statusCode;        public ResponseWrapper(){          lstaccounts = new list&lt;Account&gt;();          isError= false;     }  }   and returning the wrapper class in the Httpget method  @RestResource(urlMapping='/accounts/*') global with sharing class AccountRestService { @HttpGet global static ResponseWrapper getAccounts() {     ResponseWrapper resWrap = new ResponseWrapper();     List&lt;Account&gt; accounts;      try {         accounts = [SELECT Id, Name FROM Account];         res.lstaccounts = accounts;     } catch (Exception e) {         RestResponse res = RestContext.response;         resWrap.isError = true;         res.responseBody = Blob.valueOf(e.getMessage()) = resWrap.errorCode;         res.statusCode = 500 = resWrap.statusCode;     }      return resWrap;   } }   but its throwing the Error message  Error: Compile Error: global methods do not support return type of ResponseWrapper at line 4 column 31
57492
I have a helper class pulling a string from an XML file. That string is a file path (so it has backslashes in it). I need to use that string as it is... How can I use it like I would with the literal command?  Instead of this:  string filePath = @"C:\somepath\file.txt";   I want to do this:  string filePath = @helper.getFilePath(); //getFilePath returns a string   This isn't how I am actually using it; it is just to make what I mean a little clearer. Is there some sort of .ToLiteral() or something?
85931
I want to open an Excel file through an Apex dialog box, then browse the information in my file line and display it with visualforce. I show you my code  public class ImportExcel {       public String fileName{get; set;}     public Blob contentFile{get;set;}     public String[] csvFileLines{get;set;}     public List&lt;String&gt; acclist{get;set;}     public String[] data{get;set;}     public ImportExcel(){         csvFileLines = new String[]{};         acclist = New List&lt;String&gt;();      } public void readFile(){         try         {             fileName=contentFile.toString();         }catch(Exception e){         ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Please upload a valid CSV document');         ApexPages.addMessage(myMsg);              return ;          }         csvFileLines=fileName.split('\n');          system.debug(csvFileLines);         for(Integer i=0;i&lt;csvFileLines.size();i++){             data=csvFileLines[i].split(',');             acclist.add(data[i]);         }     } }   Once I execute my code, it puts me this error:     13:52:13:012 VARIABLE_ASSIGNMENT   [15]|e|"common.apex.runtime.impl.ExecutionException: BLOB is not a   valid UTF-8 string"|0x4e4728
14419
My below test fails because of Run Failures: TestRangehoodObjectionSheet.RangehoodObjectionSheetTest Methods defined as TestMethod do not support getContent call. I added the Blob thinking it might resolve but it doesn't work. What could be the problem here? Have I used the Blob correctly?  @isTest public with sharing class TestRangehoodObjectionSheet {      static testMethod void RangehoodObjectionSheetTest() {             String Build                = NBATRecords.getIdFromDeveloperName('Plan_Reviews__c','Building_Plan_Review');             Account a = new Account(Name = 'Test1' ,Type = 'Lead Acct',BillingState = 'CA',Industry = 'Business Services');             insert a;              Establishment_Record__c er = new Establishment_Record__c(Account__c=a.Id ,Project_Name__c = 'TestPreet',PremiseStreet__c='Manhattan ave',PremiseBorough__c='Manhattan',PremiseState__c='NY',PremisePostalCode__c='11102',Referral_Source__c='311',Data_Source__c='CAMIS',Phase__c='Initiate',Business_Status__c='Open' );             insert er;              Application__c ap = new Application__c(Establishment_Record__c=er.Id,Job_Number__c='222222222');             insert ap;              Plan_Reviews__c pr = new Plan_Reviews__c(Application__c =ap.Id ,DOB_Job_Number__c='222222222',RecordTypeId =Build,Objections__c='Pipe size not indicated');             insert pr;             PageReference pageRef = Page.RangehoodObjectionSheet;              Test.setCurrentPage(pageRef);               Blob content = Test.isRunningTest() ? Blob.valueOf('UNIT.TEST') : pageRef.getContent();              Plan_Reviews__c              p   = new Plan_Reviews__c(id=pr.Id);                ApexPages.StandardController sc  = new ApexPages.standardController(p);             System.assertNotEquals(sc,null);             RangehoodObjectionExtention    ext = new RangehoodObjectionExtention(sc);              ext.Savecopy();       } }   Actual class for the test:  public with sharing class RangehoodObjectionExtention { private final ApexPages.StandardController controller; private final Id                           planreviewID; public String imageURL{get;set;} public List&lt;String&gt; objlist {get;set;}  public string currentdate {get; set;}    public RangehoodObjectionExtention (ApexPages.StandardController stdController) {         controller   = stdController;         planreviewID = (Id)controller.getRecord().get('Id');         Date dt = Date.today();         currentdate = dt.format();         list&lt;Plan_Reviews__c&gt; prlist = [select FDNY_Objections__c from Plan_Reviews__c where id = :planreviewID limit 1];         string obj;         for(Plan_Reviews__c pr: prlist){            obj = pr.FDNY_Objections__c;             }         if(obj!=null){            list&lt;string&gt; objections = obj.split(';');             integer i =1;            objlist = new list&lt;string&gt;();            for(string o : objections){               objlist.add(i++ +'. '+o);            }         }         imageURL='/servlet/servlet.FileDownload?file=';         List&lt; document &gt; documentList=[select name from document where Name='RangehoodObjectionLogo'];         if(documentList.size()&gt;0)         {            imageURL=imageURL+documentList[0].id;         }       }          public PageReference Savecopy(){       PageReference p = Page.RangehoodObjectionSheet;       blob b = ApexPages.currentPage().getContentAsPDF ();       Attachment a = new Attachment();       a.body = b;       a.name = 'Rangehood Objection sheet Issued '+currentdate+'.pdf';       a.parentid = planreviewID;        insert a;        PageReference pref = new PageReference('/'+planreviewID);       return pref;    } }