Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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");
                }
                //Thread.sleep(200);

                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();
            //Log.e("TINTERACT","Type:"+ type);
            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");
 

                    //Log.e("TINTERACT","reading loop started");
                    //Log.e("TINTERACT", "msg"+cli.BufferedReader().readLine().toString());

 
                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);
 

                //working = false;

            } 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
Posted 8-Jun-13 11:32am
Edited 8-Jun-13 23:57pm
v3
Comments
Sergey Alexandrovich Kryukov at 8-Jun-13 23:28pm
   
The mere fact that you do Thread.sleep(1000) already tells that you are doing something wrong.
As to the exception... at least mark the place when it's thrown in source code. Normally, it should be comprehensive exception information.
And how about doing it under debugger to see what is null?
—SA
shanalikhan at 9-Jun-13 5:02am
   
I have removed the thread.sleep , and improved the question please a look on second snippet , i have written where im getting exception in while loop , and i have written the exception
also there is nothing problem in first snippet the time read the files name are sent , it sent successfully all the files names in thw while loop.
Sergey Alexandrovich Kryukov at 9-Jun-13 13:07pm
   
Wait a second. The problem with Sleep is not that you should removed it. I think you had some reason for waiting. Why?
You did not "write the exception", you wrote some string. What is it, Exception.Message? Hard to believe, but this is not comprehensive exception information. What line of code?
—SA
shanalikhan at 10-Jun-13 5:55am
   
i wrote sleep thinking that it should wait while the other thread will write the file name till 1000 .
it is the exception , you can see that exception i shown in error + getmessage so its the exception i am getting also i checked the bufferedreader.ready , it always remains as false.
Sergey Alexandrovich Kryukov at 10-Jun-13 8:59am
   
That's the whole point: how do you know a thread will write anything for 1 sec? This is the total abuse and not a working technique. With exception... what are you talking about?...
—SA
shanalikhan at 10-Jun-13 11:26am
   
actually the exception im getting is that which i am getting from ex.getmessage() as you can see.
i tried to check buffrdr.ready() which return false , it should return true so that readline would work but its returning false.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 9 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100