So i have 2 Files in the same Folder. "example.csv" and "example.jpg" but when i run this code, I get the path for example.jpg but loading the example.csv throws a Nullpointer.  System.out.println(this.getClass().getResource("/example.csv").getFile()); System.out.println(this.getClass().getResource("/example.jpg").getFile());   Thx for any help
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?
58650
I have a StringProperty(subtype="FILE_PATH) and I am trying to make it so the user selects a folder and then a file is saved out to the location, but the filepath comes out looking really funky.  The folder selected is D:\Pictures, what the StringProperty shows is //..\..\. What is going on here?
58268
In Java, given a java.net.URL or a String in the form of http://www.example.com/some/path/to/a/file.xml , what is the easiest way to get the file name, minus the extension? So, in this example, I'm looking for something that returns "file".   I can think of several ways to do this, but I'm looking for something that's easy to read and short.
34841
I've recently searched how I could get the application's directory in Java. I've finally found the answer but I've needed surprisingly long because searching for such a generic term isn't easy. I think it would be a good idea to compile a list of how to achieve this in multiple languages.  Feel free to up/downvote if you (don't) like the idea and please contribute if you like it.  Clarification:  There's a fine distinction between the directory that contains the executable file and the current working directory (given by pwd under Unix). I was originally interested in the former but feel free to post methods for determining the latter as well (clarifying which one you mean).
104361
I have a test class which calls a method from a helper class :  @isTest private class OpportunityCheckTest {      private CheckTestHelper helper = new CheckTestHelper();      @isTest     static void checkTest() {          helper.incrementCount();  &lt;-- ERROR INDICATES THIS LINE      } }   At the moment when I try to save my file, I'm getting the following error:  Result: [DEPLOYMENT FAILED]: OpportunityCheckTest.cls: Variable does not exist: helper     Can anyone explain what the problem is here?
53704
What I am doing is converting mp3's with LAME. I already have an old script I wrote that works but I want to add to it this ability--to no longer delete the file but instead save it in a new root folder with sub-directories that match the using the path that it is already in.  This is the code I got off the Internet that I am using in my script to get the path:   c=$FILENAME  xpath=${c%/*}   xbase=${c##*/}  xfext=${xbase##*.}  xpref=${xbase%.*}  path=${xpath}  pref=${xpref}  ext=${xfext}   The xpath and path give me the directory structure /home/user/working-root-directory/band-folder/album-name/  Using that technique, how do I script this to get just the band-folder into a separate variable and the album-folder into a separate variable?  Then I can use them to create  new folders keeping all the mp3s in band album order to put them into a different root folder; this would eliminate me from having to move them myself so the next time I run my script I will not re-sample them again because they will no longer be in the working directoy path/folders and still have a back up copy of my files just in case.
98247
I feel dumb asking this question, but I can't find solution to this myself.  When I open several files in editor and switch between them, I have problem finding currently opened file in project or files tree.  I used Eclipse before and every time I changed a tab with file, the project tree set focus for the same file. Is there a way to do something like this in NetBeans?
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.
92456
Alright, I have been doing the following (variable names have been changed):   FileInputStream fis = null; try {     fis = new FileInputStream(file);      ... process ...  } catch (IOException e) {     ... handle error ... } finally {     if (fis != null)         fis.close(); }    Recently, I started using FindBugs, which suggests that I am not properly closing streams.  I decide to see if there's anything that can be done with a finally{} block, and then I see, oh yeah, close() can throw IOException.  What are people supposed to do here?  The Java libraries throw too many checked exceptions.
56431
I'm going crazy...  I have a file I want to include which path is C:\Users\Matthieu\Documents\Folder withOneSpace\myFile.tex. (As you can see with the \, I'm on windows actually)  I tried the following but none works:  \input{C:/Users/Matthieu/Documents/Folder withOneSpace/myFile} \input{C:/Users/Matthieu/Documents/Folder\ withOneSpace/myFile} \input{C:/Users/Matthieu/Documents/Folder withOneSpace/myFile.tex} \input{C:/Users/Matthieu/Documents/Folder\ withOneSpace/myFile.tex}   I also tried to put the file out of the folder with a space and it works (no surprise):  \input{C:/Users/Matthieu/Documents/myFile} --&gt; Works   All I found is to put a \ before the space but it doesn't work at all. --> Please help ! :)
46094
I am trying to display a list of all files found in the selected directory (and optionally any subdirectories). The problem I am having is that when the GetFiles() method comes across a folder that it cannot access, it throws an exception and the process stops.  How do I ignore this exception (and ignore the protected folder/file) and continue adding accessible files to the list?  try {     if (cbSubFolders.Checked == false)     {         string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);         foreach (string fileName in files)             ProcessFile(fileName);     }     else     {         string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories);         foreach (string fileName in files)             ProcessFile(fileName);     }     lblNumberOfFilesDisplay.Enabled = true; } catch (UnauthorizedAccessException) { } finally {}
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
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();     } }
7898
The StackExchange app crashes for me on every start when I click a link in the browser. It seems (based on the StackTrace) that the url parser causes a null pointer exception. I'm using 0.1.90.
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?
69573
I'm trying to do something like   URL clientks = com.messaging.SubscriptionManager.class.getResource( "client.ks" ); String path = clientks.toURI().getPath(); System.setProperty( "javax.net.ssl.keyStore", path);   Where client.ks is a file stored in com/messaging in the jar file that I'm running.  The thing that reads the javax.net.ssl.keyStore is expecting a path to the client.ks file which is in the jar. I'd rather not extract the file and put in on the client's machine if possible. So is it possible to reference a file in a jar?  This doesn't work as getPath() returns null. Is there another way to do this?
19866
When running a Java app from eclipse my ImageIcon shows up just fine.  But after creating a jar the path to the image obviously gets screwed up.  Is there a way to extract an image from the jar at runtime so I can then open it up?  Or, is there a better way to do this?  I'd like to distribute a single jar file if possible.