Re: retrieving a list of file name in popup button

"Jerry W. Walker" <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Hi, Yamuna,

First, please keep your responses to the list rather than to an  
individual. Doing so allows you to draw answers from the entire  
community.

If your NullPointerException was thrown by the prototype for the  
method getAllfiles, as you indicate, then WO is complaining that the  
value returned by the method is null when it was expecting a non-null  
value.

As I looked through the code for that method, I notice that if the  
first statement of the method:

     if (downloadDir.exists() == false) {

evaluates to true (that is, downloadDir does not exist), then  
fileArray is never initialized, so the method would return a null  
result thereby throwing the exception.

You might try changing the getAllfiles() method to the following:

     public NSMutableArray getAllfiles() {
     	if (downloadDir.exists() == false) {
     		downloadFeilmelding= "directory not found!";
     		fileArray = NSMutableArray.EmptyArray;
     	} else {
          	File files[] = downloadDir.listFiles();
          	for (int i = 0; i < files.length; i++) {
         		fileArray =new NSMutableArray(files[i]);
         	}
     	}
     	return fileArray;
     }

Doing this would cause your method to return an empty array instead  
of a null value if the downloadDir does not exist.

For an array variable, there is a significant difference between an  
empty array value (a value referencing a real array which happens to  
hold no objects) and a null array value (a Java null value)

Regards,
Jerry

On Aug 14, 2006, at 6:18 AM, Yamuna Vallipuram wrote:

>
> On 13. aug. 2006, at 15.35, Jerry W. Walker wrote:
> Hi Jerry...
>
> Thank you the the response.
>
>> Hi, Yamuna,
>>
>> I don't see any obvious problems with the code you shared, but  
>> information is missing.
>>
>> It would help to know:
>>
>>   * which line in the code you showed us was line 122 (that is,  
>> which line threw the exception).
>>
> line 122  is
> public NSMutableArray getAllfiles() {
>
>>   * how you've defined downloadDir and enFile
>>
>>   * whether, and to what, you've bound your popup button's item  
>> binding
>
> My pop-up bindings look like this:
>
> stringDisplay 	getFilename
> List				getAllfiles
> Item				aFile
> Selection		selectedFile
>
> My code:
> File			aFile, selectedFile, downloadDir
>
> public NSMutableArray getAllfiles() {
>     	if (downloadDir.exists() == false) {
>     		downloadFeilmelding= "directory not found!";
>     	} else {
>          File files[] = downloadDir.listFiles();
>          for (int i = 0; i < files.length; i++) {
>         		fileArray =new NSMutableArray(files[i]);
>          }
>     	}
>     return fileArray;
>     }
>
>     public String getFilename() {
>     	String tmp;
>     	tmp = aFile.getName();
>     	return tmp;
>     }
>
> Regards Yamuna
>
>>
>> Clearly, some variable that you're expecting to have a value is  
>> instead set to null, but it would be hard to figure that out with  
>> what you've shown us.
>>
>> On Aug 13, 2006, at 8:46 AM, Yamuna Vallipuram wrote:
>>
>>> Hi...
>>>
>>> I am quite new to WebObject so I have a question retrieving file  
>>> names from a path and displaying them in a popup button,
>>>
>>> my popup button list binding is getAllfiles
>>> and stringDispaly is getFilename
>>>
>>> When I try run the project I get en error message  at  
>>> PersonImport1.getAllefiler(PersonImport1.java:122)-  
>>> NullPointerException. My codes returns the correct directory  
>>> path, but I am unable to retrieve the files. What am I doing  
>>> wrong here...
>>>
>>>
>>> public NSMutableArray getAllfiles() {
>>>     	if (downloadDir.exists() == false) {
>>>     		downloadFeilmelding= "directory not found!";
>>>     	} else {
>>>          File files[] = downloadDir.listFiles();
>>>          for (int i = 0; i < files.length; i++) {
>>>         		fileArray =new NSMutableArray(files[i]);
>>>          }
>>>     	}
>>>     return fileArray;
>>>     }
>>>
>>>     public String getFilename() {
>>>     	String tmp;
>>>     	tmp = enFil.getName();
>>>     	return tmp;
>>>     }
>>>
>>> Any help will be appreciated
>>> regards Yamuna
>>> _______________________________________________
>>> WebObjects-dev mailing list
>>> [email protected]
>>> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
>>
>>
>> --
>> __ Jerry W. Walker,
>>    WebObjects Developer/Instructor for High Performance Industrial  
>> Strength Internet Enabled Systems
>>
>>     [email protected]
>>     203 278-4085        office
>>
>>
>>
>


--
__ Jerry W. Walker,
    WebObjects Developer/Instructor for High Performance Industrial  
Strength Internet Enabled Systems

     [email protected]
     203 278-4085        office
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.