Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User preeti.s.patil's Avatar
    Join Date
    Jan 2011
    Posts
    10
    Hi,


    I am trying to implement IAP api's in my existing MIDlet. For this,I setup my Nokia SDK1.1 emulator.
    But, when i run it, I am unable to get the instance of IAPClientPaymentManager.

    My code is like this,
    manager = IAPClientPaymentManager.getIAPClientPaymentManager();



    Please help...

  2. #2
    Nokia Developer Expert skalogir's Avatar
    Join Date
    Aug 2011
    Posts
    547
    Hi preeti,

    This looks correct. What is the error that you get?

    Would you still have trouble, if you were to use this sample code:
    Code:
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.StringItem;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import com.nokia.mid.payment.IAPClientPaymentException;
    import com.nokia.mid.payment.IAPClientPaymentListener;
    import com.nokia.mid.payment.IAPClientPaymentManager;
    import com.nokia.mid.payment.IAPClientProductData;
    import com.nokia.mid.payment.IAPClientUserAndDeviceData;
    
    public class IAPtest 
    	extends MIDlet 
    	implements IAPClientPaymentListener, CommandListener {
    	
    	Form mainForm;
    	Display display;
    	Command retrieveCommand = new Command("Info", Command.OK, 0);
    	Command exitCommand = new Command("Exit", Command.EXIT, 0);
    	StringItem info = new StringItem("Product Data", ""); //Displays either Product Data or Error messages
    	
    	protected void startApp() throws MIDletStateChangeException {
    		//The main Screen's components
    		display = Display.getDisplay(this);
    		mainForm = new Form("In App Purchase");
    		mainForm.addCommand(exitCommand);
    		mainForm.addCommand(retrieveCommand);
    		mainForm.setCommandListener(this);
    		mainForm.append(info);
    		display.setCurrent(mainForm);
    	}
    	
    	//Call back method that is asynchronously called after invoking the getProductData method
    	public void productDataReceived(int status, IAPClientProductData pd) {
    	    if (status == IAPClientPaymentListener.OK) {
    	    	
    	    	String title = pd.getTitle();
    	        String price = pd.getPrice();
    	        String sdesc = pd.getShortDescription();
    	        
    	        String output = "";
    	        output = "Title:"+title+"\n";
    	        output = output + "Price:"+price+"\n";
    	        output = output + "Short Description:" + sdesc + "\n";
    	        
    	        info.setText(output);
    	    }	
    	    else {
    	    	mainForm.append("Product data retrieval failed with code:" + status);
    	    }
    	}
    
    	public void commandAction(Command c, Displayable d) {
    		if(c == retrieveCommand) {
    			
    			try {
    			    IAPClientPaymentManager manager = IAPClientPaymentManager.getIAPClientPaymentManager();
    			    IAPClientPaymentManager.setIAPClientPaymentListener(this);
    			    int status = manager.getProductData("681803"); //BattleTank's Product ID
    			    if (status != IAPClientPaymentManager.SUCCESS) {
    			    	info.setText("Do not expect a callback \n");
    			    }
    			} 
    			catch (IAPClientPaymentException e) {
    				info.setText("IAPClientPaymentException:" + e.getMessage() + "\n");
    			}
    			catch(Exception e) {
    				info.setText("Exception:" + e.getMessage() + "\n");
    			}
    		}
    		
    		if(c == exitCommand) {
    			notifyDestroyed();
    		}
    		
    	}
    	
    	public void purchaseCompleted(int arg0, String arg1) {
    		//To do
    	}
    	
    	public void userAndDeviceDataReceived(int arg0,IAPClientUserAndDeviceData arg1) {
    		//To do
    	}
    	
    	public void productDataListReceived(int arg0, IAPClientProductData[] arg1) {
    		//To do
    	}
    	
    	public void restorableProductsReceived(int arg0, IAPClientProductData[] arg1) {
    		//To do
    	}
    	
    	public void restorationCompleted(int arg0, String arg1) {
    		//To do
    	}
    	
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    		//To do
    	}
    	protected void pauseApp() {
    		//To do
    	}	
    }
    and you ensured that you created your In-App resource files according to this guide ?

Similar Threads

  1. NullPointerException
    By briandaly40 in forum Mobile Java General
    Replies: 4
    Last Post: 2012-03-12, 06:51
  2. NullPointerException!!!!!
    By anshul.newlife in forum Mobile Java Games
    Replies: 7
    Last Post: 2010-09-14, 10:14
  3. getLocation always throws NullPointerException
    By Wurstgesicht in forum Geolocation and Navigation
    Replies: 5
    Last Post: 2009-03-20, 13:08
  4. Using RecordStore.AUTHMODE_ANY throws NullPointerException
    By sgaber in forum Mobile Java General
    Replies: 10
    Last Post: 2007-12-18, 18:03
  5. recordcontrol.setStream(out) throws NullPointerException
    By bharatdevada in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-11-10, 01:16

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved