Hi ,
Im getting null as exception message when i try to read string in andorid device from PC.
following is the code where PC gets the location from andorid and send the files and directories under some folder.
public void HandleCommands() throws Exception{
System.out.println("CLIENT - Sending Files");
tmp = ser.BufferedReader().readLine();
System.out.println(tmp);
if(tmp.equals("LISTFILES")){
String path = ser.BufferedReader().readLine();
System.out.println("CLIENT - path"+ path);
File[] fl = new File(path).listFiles();
for(int i=0;i<fl.length;i++){
if(!fl[i].isHidden()){
if(fl[i].isDirectory())
{
ser.OutputStream().write("Folder".getBytes());
ser.OutputStream().write("\n".getBytes());
ser.OutputStream().flush();
ser.OutputStream().write(fl[i].getPath().getBytes());
ser.OutputStream().write("\n".getBytes());
ser.OutputStream().flush();
System.out.println("Folder");
}
else if(fl[i].isFile()){
ser.OutputStream().write("File".getBytes());
ser.OutputStream().write("\n".getBytes());
ser.OutputStream().flush();
ser.OutputStream().write(fl[i].getPath().getBytes());
ser.OutputStream().write("\n".getBytes());
ser.OutputStream().flush();
System.out.println("File");
}
System.out.println(fl[i].getPath());
}
}
}
ser.OutputStream().write("END".getBytes());
ser.OutputStream().write("\n".getBytes());
ser.OutputStream().flush();
System.out.println("End");
}
while , im getting the error in andorid device when reading the file names. following is my code :
public void ListFiles(String path, String type){
try{
working= true;
Log.e("TINTERACT", "Listing path getting");
cli.OutputStream().write("LISTFILES".getBytes());
cli.OutputStream().write("\n".getBytes());
cli.OutputStream().flush();
if(type.equals("Folder")){
cli.OutputStream().write(path.getBytes());
cli.OutputStream().write("\n".getBytes());
cli.OutputStream().flush();
String line=null;
Log.e("TINTERACT", "Start Getting files names");
String text="";
while((line=cli.BufferedReader().readLine())!=null) -----GETTING EXCEPTION HERE
{
Log.e("TINTERACT", line);
fileType.add(line);
String a = cli.BufferedReader().readLine();
fileNames.add(a);
Log.e("TINTERACT", line+ ":"+a);
}
Log.e("TINTERACT", text);
} else if(type.equals("File")){
}
}
catch(Exception ex){
Log.e("TINTERACT", "ERROR - "+ex.getMessage());
}
}
when the while loop start i get the NULL as message of exception.
FOLLOWING IS THE EXCEPTION :
06-09 13:54:56.333: E/TINTERACT(5012): ERROR - null