Hi Murphy,

I just made code change to get rid of NullPointerException by creating
YahooClient object (by new YahooClient())

------------------------
//Part of ChallengeResponseV10.java code where challenge.bin is read

class ChallengeResponseV10 extends ChallengeResponseUtility
implements ChallengeResponseV10Tables
{
......
......
// -----Buffer for binary data, and resource filename
private static byte[] data;
private final static String BIN_FILE="challenge.bin";

// -----------------------------------------------------------------
// Load binary data tables as a resource from /ysmg/network/BIN_FILE
// -----------------------------------------------------------------
static
{       try
        {       // -----Open stream to resource located next to this
class
                Class v10 = Class.forName
("ymsg.network.ChallengeResponseV10");
                YahooClient     yahooClient  =  new YahooClient();
                InputStream     istream = yahooClient.retInputStream
();
                //DataInputStream dis = new DataInputStream
(v10.getResourceAsStream (BIN_FILE));
                DataInputStream dis = new DataInputStream(istream);
                System.out.println("ChallengeResponseV10: available
bytes value:");
                System.out.print(dis.available());
                data = new byte[dis.available()];
                // -----Extra entry at end of offset table has entire
file size
                if(data.length<TABLE_OFFSETS[TABLE_OFFSETS.length-1])
                        throw new Exception("Data too short?");
                // -----Read binary data into array
                dis.readFully(data);
                dis.close();
        }
        catch(Exception e)
        {       System.err.println("Error loading resource file: ");
                e.printStackTrace();
        }
}
-------------------------------------

I am getting following error as seen in Logcat

--------------------------------------
java.lang.RuntimeException: Can't create handler inside thread that
has not called Looper:prepare()
  at android.os.Handler.<init>(Handler.java:111)
  at android.app.Activity.<init>(Activity.java:660)
  at AndJYMSG.YahooClient.<init>(YahooClient.java:20)
  at ymsg.network.ChallengeResponseV10.<clinit>
(ChallengeResponseV10.java:73)
  at ymsg.network.Session.receiveAuth(Session.java:1114)
  at ymsg.network.Session$InputThread.process(Session.java:2322)
  at ymsg.network.Session$InputThread.run(Session.java:2293)
-------------------------------------

---------------------------
//The source code of Session.receiveAuth() is as follows
        protected void receiveAuth(YMSG9Packet pkt)                     // 0x57
        throws IOException,NoSuchAlgorithmException
        {       String v10 = pkt.getValue("13");                                
        // '0'=v9, '1'=v10
                String[] s;
                try
                {       if(v10!=null && !v10.equals("0"))
                        {
                                
s=ChallengeResponseV10.getStrings(loginID,password,pkt.getValue
("94"));
                        }
                        else
                        {
                                
s=ChallengeResponseV9.getStrings(loginID,password,pkt.getValue
("94"));
                        }
                }
                catch(NoSuchAlgorithmException e) { throw e; }
                catch(Exception e) { throw new YMSG9BadFormatException
("auth",false,e); }
                transmitAuthResp(s[0],s[1]);
        }
--------------------------------------------

---------------------------------------
// Source code of Session$InputThread.process

                // -----Switch on packet type to handler code
                void process(YMSG9Packet pkt) throws Exception
                {       // -----A null packet is sent when the input stream 
closes
                        if(pkt == null) { quit=true;  return; }
                        // -----Process header
                        if(pkt.sessionId!=0)                            // Some 
chat packets send zero
                                sessionId = pkt.sessionId;              // 
Update sess id in outer class
                        // -----Error header?
                        if(pkt.status==-1 && processError(pkt)==true) return;
                        // -----Process payload
                        switch(pkt.service)                             // Jump 
to service-specific code
                        {       case SERVICE_ADDIGNORE :        
receiveAddIgnore(pkt);  break;
                                case SERVICE_AUTH :             
receiveAuth(pkt);  break;
                                case SERVICE_AUTHRESP :         
receiveAuthResp(pkt);  break;
                                case SERVICE_CHATCONNECT :      
receiveChatConnect(pkt);  break;
                                case 
SERVICE_CHATDISCONNECT:receiveChatDisconnect(pkt);  break;
                                case SERVICE_CHATLOGOFF :       
receiveChatLogoff(pkt);  break;
                                case SERVICE_CHATLOGON :        
receiveChatLogon(pkt);  break;
                                case SERVICE_CHATMSG :          
receiveChatMsg(pkt);  break;
                                case SERVICE_CHATPM :           
receiveChatPM(pkt);  break;
                                case SERVICE_CONFADDINVITE:     
receiveConfAddInvite(pkt);  break;
                                case SERVICE_CONFDECLINE :      
receiveConfDecline(pkt);  break;
                                case SERVICE_CONFINVITE :       
receiveConfInvite(pkt);  break;
                                case SERVICE_CONFLOGOFF :       
receiveConfLogoff(pkt);  break;
                                case SERVICE_CONFLOGON :        
receiveConfLogon(pkt);  break;
                                case SERVICE_CONFMSG :          
receiveConfMsg(pkt);  break;
                                case SERVICE_CONTACTIGNORE:     
receiveContactIgnore(pkt);  break;
                                case SERVICE_CONTACTNEW :       
receiveContactNew(pkt);  break;
                                case SERVICE_FILETRANSFER : 
receiveFileTransfer(pkt);  break;
                                case SERVICE_FRIENDADD :        
receiveFriendAdd(pkt);  break;
                                case SERVICE_FRIENDREMOVE :     
receiveFriendRemove(pkt);  break;
                                case SERVICE_IDACT :            
receiveIdAct(pkt);  break;
                                case SERVICE_IDDEACT :          
receiveIdDeact(pkt);  break;
                                case SERVICE_ISAWAY :           
receiveIsAway(pkt);  break;
                                case SERVICE_ISBACK :           
receiveIsBack(pkt);  break;
                                case SERVICE_LIST :             
receiveList(pkt);  break;
                                case SERVICE_LOGOFF :           
receiveLogoff(pkt);  break;
                                case SERVICE_LOGON :            
receiveLogon(pkt);  break;
                                case SERVICE_MESSAGE :          
receiveMessage(pkt);  break;
                                case SERVICE_NEWMAIL :          
receiveNewMail(pkt);  break;
                                case SERVICE_NOTIFY :           
receiveNotify(pkt);  break;
                                case SERVICE_PING :                     
receivePing(pkt);  break;
                                case SERVICE_USERSTAT :         
receiveUserStat(pkt);  break;
                                default : System.out.println("UNKNOWN: 
"+pkt.toString());  break;
                        }
                }

                // -----Called when status == -1.  Returns true if no further
processing is
                // -----required (process() returns) otherwise false (process()
continues).
                boolean processError(YMSG9Packet pkt) throws Exception
                {       switch(pkt.service)                             // Jump 
to service-specific code
                        {       case SERVICE_AUTHRESP :         
receiveAuthResp(pkt);  return true;
                                case SERVICE_CHATLOGON :        
receiveChatLogon(pkt);  return true;
                                case SERVICE_LOGOFF :           
receiveLogoff(pkt);  return true;
                                default : errorMessage(pkt,null);  return 
(pkt.body.length<=2);
                        }
                }
        }
------------------------------------------------


------------------------------
//The source code of Session$InputThread.run

        private class InputThread extends Thread
        {       public boolean quit=false;                              // Exit 
run in J2 compliant way

                // -----Start input thread
                public InputThread() { super(ymsgThreads,"Network Input");
this.start(); }

                // -----Accept packets and send them for processing
                public void run()
                {       try
                        {       // -----Dies when (a) a LOGOFF packet sets 
quit, or (b) a null
                                // -----packet is sent to process().
                                while(!quit)
                                {       try
                                        {       
process(network.receivePacket());
                                        }catch(Exception e)
                                        {       try
                                                {       SessionExceptionEvent 
se = new SessionExceptionEvent
(Session.this,"Source: InputThread",e);
                                                        new 
FireEvent().fire(se,SERVICE_X_EXCEPTION);
                                                }catch(Exception e2) { 
e2.printStackTrace(); }
                                        }
                                }
                        }
                        finally
                        {       // -----Terminate (note: network may already 
have been closed if
                                // -----the loop terminated due to a lost 
connection).
                                closeNetwork();
                                new FireEvent().fire(new 
SessionEvent(this),SERVICE_LOGOFF);
                        }
                }
----------------------------------------

I guess now you have better idea of the problem and I guess you are in
a better position to advise me now.

Thanks
 Maddy


On Feb 9, 3:33 pm, Mark Murphy <[email protected]> wrote:
> Maddy wrote:
> > To give more information, I had put break point at
>
> > InputStream     istream = yahooClient.retInputStream();
>
> > in the code snippet I had put before in this conversation.
>
> > When the control hits this break point, I pressed F5 (I am using
> > Eclipse IDE) to go into the function,
> > but instead of going into the function, it straight aways throws
> > NullPointerException.
>
> > may be the above information too helps you in helping me.
>
> When I asked "What is the exception?" in my previous reply, I meant
> "What is the exception?". I am assuming, from your above message, that
> the exception is a NullPointerException.
>
> If you are getting a NullPointerException on the above line, yahooClient
> is presumably null. You did not provide any source code indicating you
> are ever creating a YahooClient object (e.g., new YahooClient()).
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> _The Busy Coder's Guide to Android Development_ Version 2.0 Published!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to