×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    10

    NullPointerException

    Hey everyone,

    I'm trying to run the following code:
    Code:
    // ReadMessages.java - Sample application.
    //
    // This application shows you the basic procedure needed for reading
    // SMS messages from your GSM modem, in synchronous mode.
    //
    // Operation description:
    // The application setup the necessary objects and connects to the phone.
    // As a first step, it reads all messages found in the phone.
    // Then, it goes to sleep, allowing the asynchronous callback handlers to
    // be called. Furthermore, for callback demonstration purposes, it responds
    // to each received message with a "Got It!" reply.
    //
    // Tasks:
    // 1) Setup Service object.
    // 2) Setup one or more Gateway objects.
    // 3) Attach Gateway objects to Service object.
    // 4) Setup callback notifications.
    // 5) Run
    
    import java.util.ArrayList;
    import java.util.List;
    import org.smslib.ICallNotification;
    import org.smslib.IInboundMessageNotification;
    import org.smslib.Library;
    import org.smslib.MessageClasses;
    import org.smslib.MessageTypes;
    import org.smslib.Service;
    import org.smslib.modem.SerialModemGateway;
    
    public class ReadMessages
    {
    	private Service srv;
    
    	public void doIt() throws Exception
    	{
    		List msgList;
    		// Create the notification callback method for Inbound & Status Report
    		// messages.
    		InboundNotification inboundNotification = new InboundNotification();
    		// Create the notification callback method for inbound voice calls.
    		CallNotification callNotification = new CallNotification();
    		try
    		{
    			System.out.println("Example: Read messages from a serial gsm modem.");
    			System.out.println(Library.getLibraryDescription());
    			System.out.println("Version: " + Library.getLibraryVersion());
    			// Create new Service object - the parent of all and the main interface
    			// to you.
    			srv = new Service();
    			// Create the Gateway representing the serial GSM modem.
    			SerialModemGateway gateway = new SerialModemGateway("modem.com6", "COM6", 57600, "Nokia", "6234");
    			// Do we want the Gateway to be used for Inbound messages? If not,
    			// SMSLib will never read messages from this Gateway.
    			gateway.setInbound(true);
    			// Do we want the Gateway to be used for Outbound messages? If not,
    			// SMSLib will never send messages from this Gateway.
    			gateway.setOutbound(true);
    			gateway.setSimPin("25273");
    			// Set up the notification methods.
    			gateway.setInboundNotification(inboundNotification);
    			gateway.setCallNotification(callNotification);
    			// Add the Gateway to the Service object.
    			srv.addGateway(gateway);
    			// Similarly, you may define as many Gateway objects, representing
    			// various GSM modems, add them in the Service object and control all of them.
    			//
    			// Start! (i.e. connect to all defined Gateways)
    			srv.startService();
    			System.out.println();
    			System.out.println("Modem Information:");
    			System.out.println("  Manufacturer: " + gateway.getManufacturer());
    			System.out.println("  Model: " + gateway.getModel());
    			System.out.println("  Serial No: " + gateway.getSerialNo());
    			System.out.println("  SIM IMSI: " + gateway.getImsi());
    			System.out.println("  Signal Level: " + gateway.getSignalLevel() + "%");
    			System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
    			System.out.println();
    			// Read Messages. The reading is done via the Service object and
    			// affects all Gateway objects defined. This can also be more directed to a specific
    			// Gateway - look the JavaDocs for information on the Service method calls.
    			msgList = new ArrayList();
    			srv.readMessages(msgList, MessageClasses.ALL);
    			for (int i = 0; i < msgList.size(); i++)
    				System.out.println(msgList.get(i));
    			// Sleep now. Emulate real world situation and give a chance to the notifications
    			// methods to be called in the event of message or voice call reception.
    			System.out.println("Now Sleeping - Hit <enter> to terminate.");
    			System.in.read();
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			srv.stopService();
    		}
    	}
    
    	public class InboundNotification implements IInboundMessageNotification
    	{
    		public void process(String gatewayId, MessageTypes msgType, String memLoc, int memIndex)
    		{
    			List msgList;
    			if (msgType == MessageTypes.INBOUND)
    			{
    				System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId + " : " + memLoc + " @ " + memIndex);
    				try
    				{
    					// Read...
    					msgList = new ArrayList();
    					srv.readMessages(msgList, MessageClasses.UNREAD, gatewayId);
    					for (int i = 0; i < msgList.size(); i++)
    						System.out.println(msgList.get(i));
    					// ...and reply.
    					//for (int i = 0; i < msgList.size(); i ++)
    					//{
    					//	InboundMessage msg = (InboundMessage) msgList.get(i);
    					//	srv.sendMessage(new OutboundMessage(msg.getOriginator(), "Got it!"), gatewayId);
    					//}
    				}
    				catch (Exception e)
    				{
    					System.out.println("Oops, some bad happened...");
    					e.printStackTrace();
    				}
    			}
    			else if (msgType == MessageTypes.STATUSREPORT)
    			{
    				System.out.println(">>> New Status Report message detected from Gateway: " + gatewayId + " : " + memLoc + " @ " + memIndex);
    			}
    		}
    	}
    
    	public class CallNotification implements ICallNotification
    	{
    		public void process(String gatewayId, String callerId)
    		{
    			System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
    		}
    	}
    
    	public static void main(String args[])
    	{
    		ReadMessages app = new ReadMessages();
    		try
    		{
    			app.doIt();
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    	}
    }

    ==================================

    But I am getting the following error when running the program:

    init:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\My Documents\NetBeansProjects\SMS\build\classes
    compile-single:
    run-single:
    Example: Read messages from a serial gsm modem.
    SMSLib: A Java API library for sending and receiving SMS via a GSM modem
    or other supported gateways.
    Web Site: http://smslib.org
    This software is distributed under the terms of the Apache v2.0 License.
    Version: 3.2.2
    java.lang.NullPointerException
    at ReadMessages.doIt(ReadMessages.java:96)
    at ReadMessages.main(ReadMessages.java:148)
    BUILD SUCCESSFUL (total time: 0 seconds)

    =================================
    Line 96 is srv.stopservice();
    Line 148 is app.doIt();

    I understand the NullPointerException but I dont know why its doing it here! Im running this in Netbeans 6.1, windows XP and I am using this example from the smslib package!

    Any help would be greatly appreciated?
    Last edited by briandaly40; 2008-06-17 at 09:31. Reason: Line descriptions was wrong

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    42

    Re: NullPointerException

    I am also getting the same problem.. However I am using the Lib version 3.3.0, but also getting the same Null Pointer Exception... I have tried an other code.. as follows
    Code:
    package org.ezzisoft.sms;
    
    import org.ietf.jgss.MessageProp;
    import org.smslib.modem.SerialModemGateway;
    import org.smslib.modem.athandler.ATHandler;
    
    public class SMSSender
    {
        ATHandler objATHandler;
        SerialModemGateway objModem;
        
        SMSSender()throws Exception
        {
            objModem = new SerialModemGateway("modem1","COM4",115200,"BanQ","M32");
            objATHandler = new ATHandler(objModem);
            System.out.println("Battery Level: "+objModem.getBatteryLevel());
            System.out.println("Manufacturer: "+objModem.getManufacturer());
        }
    
        /**
         * @param args
         */
        public static void main(String[] args)
        {
            // TODO Auto-generated method stub
            try
            {
                new SMSSender();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
    
        }
    
    }
    Why it is so, can anyone send me the code which can communicate with a GSM modem connected to Serial Port.. Please I need urgent help..
    Muhammad Ummar Iqbal Bhutta
    Student (Computer Engineering)
    University of Engineering and Technology Lahore

  3. #3
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: NullPointerException

    shouldnt u use a variable name ?
    as in

    SMSSender mySender = new SMSSender();

    instead of ur

    new SMSSender();

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    1

    Re: NullPointerException

    Hi briandaly40, I got the same error.Have you recovered that error?If so plz help me.bcz i am doing my final year project based on that.I spend so much of my time on working about how to recover it.But I am unable to find the reason. plzz....help me to solve the problem..
    Thanks in advance.....
    my email id is:gpriyankarael126@gmail.com.

  5. #5
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: NullPointerException

    Hello priyanka.gunde,

    and welcome to Nokia Developer Discussion Boards!

    Please note that last time this discussion took place was almost four years ago so some of the stakeholders might not be online.

    If the issue is related to the smslib, you could find more information and support also from the site of the project: http://smslib.org/

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

Similar Threads

  1. Using RecordStore.AUTHMODE_ANY throws NullPointerException
    By sgaber in forum Mobile Java General
    Replies: 10
    Last Post: 2007-12-18, 18:03
  2. recordcontrol.setStream(out) throws NullPointerException
    By bharatdevada in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-11-10, 01:16
  3. NullPointerException on application exit
    By phillipsl in forum Mobile Java General
    Replies: 1
    Last Post: 2005-02-14, 09:14
  4. Weird NullPointerException
    By baegsi in forum Mobile Java General
    Replies: 8
    Last Post: 2003-12-19, 11:12
  5. How to display trace stack for nullPointerException?
    By kokohead in forum Mobile Java General
    Replies: 1
    Last Post: 2003-02-22, 20:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×