English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

the first is :
I have a variable "root" that the type is "File" and I want to convert "File" to "String".
so it must be like that:
String path = (String) root + fileNames[i].getName();
so how can I change the type of "root"?
the second is :
I have imported all this libraries :
import java.util.*;
import java.io.*;
import java.nio.*;
import java.lang.*;
import java.*;
but I have like error :
symbol : method isDirectory()
location: class java.lang.String
if ( fileNames[i].isDirectory()) {
symbol : method getName()
location: class java.lang.String
String path = root + fileNames[i].getName()
it don't know the methods getName() and isDirectory()

2007-05-09 02:33:37 · 2 answers · asked by Sepehr 2 in Computers & Internet Programming & Design

the first problem has resolve by Jim Mary
the response was the methode toString.
but the second is not resolve.

2007-05-09 03:07:25 · update #1

the second problem has resolve.
the solution was the type of "fileNames" because the type was String and isDirectory() and getName() are the methodes of type File.

2007-05-09 03:45:19 · update #2

I have a third question:
I have like error message this one:
Exception in thread "main" java.lang.NullPointerException
at frag.Main.main(Main.java:41)
and the code is :
................
int inode=0;
try {
fs=frag.FileSystem.getInstance(3);
}
catch(IOException exception) {
System.out.println("IOexception");
fs=null;
}

map=new CompleteMemoryMap(4096);
newMap=new CompleteMemoryMap(4096);

Vector files=fs.getRemixFiles();

Iterator list=files.iterator();
while (list.hasNext()) {
RemixFile rf;
rf=list.next();
map.add(rf.getFileMap());
newMap.add(rf.getFileMap());
}
.......
what can I do?

2007-05-09 03:48:21 · update #3

2 answers

The class File has a "toString()" method that will return the name of the file. What you are trying to do with the line "String path = (String)root ..." is cast a File object to a String object and you should be seeing a ClassCastException.

** Edit **
Have you declared the "frag" variable anywhere? Has it been initialized? I can't tell if the initialization for the "frag" variable was done earlier as you only have a fragment of your code posted (which is fine, just hard to know what has been set earlier). Generally a NullPointerException is when you have a variable that you haven't initialized.

Example:

// Initialize variables outside of a try block
String abc = null;

try {
// some code
// ...
//

// should have a line initializing abc to a string but for
// the example, I'll just leave it commented.

// abc = foo.getString();

}

// This throws the NullPointerException because it wasn't actually initialized to anything.
System.out.println("abc = " + abc);

These types of errors can be a real pain as most IDEs don't check for that error and you only catch it at runtime.

2007-05-09 02:56:11 · answer #1 · answered by Jim Maryland 7 · 2 0

http://answers.yahoo.com/question/index?qid=20070509063938AAaWa4x&pa=FYd1D2bwHTHwI7JhFe0yScaO00h8F6j7fgcdtEeec5wcTw--&paid=asked&msgr_status=
pls need help

2007-05-09 02:42:00 · answer #2 · answered by Anonymous · 0 2

fedest.com, questions and answers