Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 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.

C#
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 :
C#
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
Updated 8-Jun-13 22:57pm
v3
Comments
Sergey Alexandrovich Kryukov 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 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 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 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 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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900