Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Post PIM Contact List inside LWUIT Tab

    I am new in j2me symbian mobile app development and I am trying to create an sms/chat app with two tabs. Tab1 contains a where the user will choose in a list of contacts and other one contains the new screen for chat. I manage to create a tab using LWUIT and I also have code in accessing the list of contacts as a new midlet. The problem is I don't know how to put it inside the tab as a component. Any suggestion/reference code how to do it? Thanks in advance!

    I managed to create some code:

    Code:
    import java.util.Enumeration;
    
    import javax.microedition.lcdui.Choice;
    import javax.microedition.lcdui.List;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;
    
    import com.sun.lwuit.Container;
    import com.sun.lwuit.Tabs;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.layouts.BoxLayout;
    
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.pim.*;
    
    import java.util.*;
    
    public class TabsDemo extends Demo {
    
        Tabs tp = null;
        List listContacts = null;
        ContactList contactList = null;
        
         public void cleanup() {
             tp = null;
         }
    
        public String getName() {
            return "";	
        }
    
        protected void executeDemo(Container f) {
            f.setLayout(new BorderLayout());
            f.setScrollable(false);
            tp = new Tabs();
    
            Container ContactListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            ContactListPanel.setScrollableY(true);        
            tp.addTab("Contacts", ContactListPanel);
            
            
    
            Container radioButtonsPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            radioButtonsPanel.setScrollableY(true);
    
    
       
            tp.addTab("Messages", radioButtonsPanel);
            
            f.addComponent("Center", tp);
            setupContactList();
          	//ContactListPanel.addComponent();
        }
        
        private void setupContactList() {
            listContacts = new List("Contact list", Choice.IMPLICIT);
            fillContactList();
        }
        
        private void fillContactList() {
            try {
        //        printString("Opening contact list ...");
                contactList = (ContactList)PIM.getInstance().openPIMList(
                        PIM.CONTACT_LIST, PIM.READ_WRITE);
    
            } catch (PIMException ex) {
      //          printString(ex.toString());
                return;
            }
            Enumeration contacts = null;
            Contact contact = null;
    /*        try {
                printString("Getting contact list items");
                contacts = contactList.items();
            } catch (PIMException ex) {
                releaseContactList();
                printString(ex.toString());
                return;
            }*/
            // Checking contact count
            if (!contacts.hasMoreElements()) {
                //printString("Contact list IS empty!");
            }
            if (listContacts.size() > 0) {
                listContacts.deleteAll();
            }
            while (contacts.hasMoreElements()) {
                contact = (Contact)contacts.nextElement();
                String contactInfo = contact.getStringArray(Contact.NAME,
                        Contact.ATTR_NONE)[Contact.NAME_GIVEN];
                if (contactInfo != null) {
                    listContacts.append(contactInfo, null);
                }
            }
        }
    
    
    }

  2. #2
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    You need to add listContacts to radioButtonsPanel container.Right now the container radioButtonsPanel is local to the function executeDemo().Make it global or restructure your code in such a way that you can add the list to the container.

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    Hi. Is that the only reason/error why the contact list is not showing in the contact tab? Can you point me to the right direction how to get this done. I'm really have limited knowledge in j2me. Thanks.

  4. #4
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    Are you getting any other error ?

    If not,then yes.You have not added the list to radioButtonsPanel
    First make radioButtonsPanel global.
    Then at the end of fillContactList method,add the list to the radioButtonsPanel container

    radioButtonsPanel.addComponent(listContacts);

  5. #5
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    I've reconstruct my code. It didn't show any error but it only display white screen on emulator.

    Here is my code:

    import java.util.Enumeration;

    import javax.microedition.lcdui.Choice;
    //import javax.microedition.lcdui.Displayable;
    //import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Display;
    //import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.List;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;


    import com.sun.lwuit.Container;
    import com.sun.lwuit.Tabs;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.layouts.BoxLayout;

    public class TabMidlet extends MIDlet {

    Tabs tp = null;
    List listContacts = new List("Contact list", Choice.IMPLICIT);
    ContactList contactList = null;
    Display display;
    Container ContactListPanel = null;

    public void cleanup() {
    tp = null;
    }

    public String getName() {
    return "";
    }

    protected void executeDemo(Container f) {
    f.setLayout(new BorderLayout());
    f.setScrollable(false);
    tp = new Tabs();
    //Form fr = new Form();

    Container ContactListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    setupContactList();
    //openContactList();
    ContactListPanel.setScrollableY(true);
    tp.addTab("Contacts", ContactListPanel);

    Container MessageListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    MessageListPanel.setScrollableY(true);
    tp.addTab("Messages", MessageListPanel);

    f.addComponent("Center", tp);


    }



    private void setupContactList() {


    openContactList();
    // releaseContactList();
    }

    /**
    * Fills listContacts fith data read from PIM database and brings
    * the list to the foreground.
    */
    private void openContactList() {

    try{
    fillContactList();
    display = Display.getDisplay(this);
    display.setCurrent(listContacts);
    printString("Done");
    }
    catch (Exception e) {
    e.printStackTrace();
    }

    }


    private void fillContactList() {
    try {
    printString("Opening contact list ...");
    contactList = (ContactList)PIM.getInstance().openPIMList(
    PIM.CONTACT_LIST, PIM.READ_WRITE);

    } catch (PIMException ex) {
    printString(ex.toString());
    return;
    }
    Enumeration contacts = null;
    Contact contact = null;
    try {
    printString("Getting contact list items");
    contacts = contactList.items();
    } catch (PIMException ex) {
    releaseContactList();
    printString(ex.toString());
    return;
    }
    // Checking contact count
    if (!contacts.hasMoreElements()) {
    printString("Contact list IS empty!");
    }
    if (listContacts.size() > 0) {
    listContacts.deleteAll();
    }
    while (contacts.hasMoreElements()) {
    contact = (Contact)contacts.nextElement();
    String contactInfo = contact.getStringArray(Contact.NAME,
    Contact.ATTR_NONE)[Contact.NAME_GIVEN];
    if (contactInfo != null) {
    listContacts.append(contactInfo, null);
    }
    }

    }

    /**
    * Closes the contact list if one is opened.
    */
    private void releaseContactList() {
    if (contactList != null) {
    try {
    printString("Closing contact list");
    contactList.close();
    } catch (PIMException ex) {
    printString(ex.toString());
    }
    }
    contactList = null;
    }

    /**
    * Prints a string on the screen.
    */
    private void printString(String text) {
    }

    protected void destroyApp(boolean unconditional)
    throws MIDletStateChangeException {

    }

    protected void pauseApp() {

    }

    protected void startApp() throws MIDletStateChangeException {

    }


    }
    Last edited by jejoybalm; 2014-04-06 at 04:24.

  6. #6
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    Hi

    You need to understand that the startApp method is called as soon as the app is launched.No other method gets called automatically.There is no code to execute in your startApp.

  7. #7
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    Hello. you're right. i already think that's my problem. i've already try some code on startApp method but it emits some error like it is not applicable for the arguments. i cant figure out what to put. can you suggest me some solution? Thanks. your help is very much appreciated.
    Last edited by jejoybalm; 2014-04-08 at 09:55.

  8. #8
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    Please post the exact error message you are getting

  9. #9
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    "The method getDisplay(MIDlet) in the type Display is not applicable for the arguments (TabsDemo)" i need to add the display method to show the contact list.

  10. #10
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    You need to pass a reference of the current MIDlet to the getDisplay method.(In most cases, using "this" should work)

    You are sending an instance of a class called TabsDemo, which I guess doenst extend MIDlet class.

  11. #11
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    Hi I've already added the contact list inside the tab but I'm encountering an error like java.lang.nullPointerException. I've declared all of the needed variable. where i could possibly go wrong?

    here is my code:

    package com.sun.lwuit.functions;

    import java.util.Enumeration;
    import java.util.Vector;

    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Item;
    import javax.microedition.lcdui.List;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;
    import javax.microedition.pim.PIMItem;
    import javax.wireless.messaging.MessageConnection;

    import com.sun.lwuit.Button;
    import com.sun.lwuit.ButtonGroup;
    import com.sun.lwuit.Command;
    import com.sun.lwuit.ComponentGroup;
    import com.sun.lwuit.Container;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Label;
    import com.sun.lwuit.RadioButton;
    import com.sun.lwuit.Tabs;
    import com.sun.lwuit.TextArea;
    import com.sun.lwuit.TextField;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.layouts.BoxLayout;
    import com.sun.lwuit.list.ListModel;
    import com.sun.lwuit.list.DefaultListModel;

    //import javax.swing.DefaultListModel;

    public class TabsDemo extends Demo
    {

    /**global declarations**/
    Tabs tp = null;
    Form c = null;
    // List listContacts = new List("Contact list", Choice.IMPLICIT);
    // ContactList contactList = null;
    Display display;
    Container ContactListPanel = null;
    ComponentGroup buttonGroup, checkboxGroup, radioGroup, textFieldGroup = null;
    //public Form form = null;
    MessageConnection clientConn;
    //private Command command1, command2;
    private Alert alertsend;
    Display myDisplay;
    Form myForm;


    private com.sun.lwuit.List contactList;
    private PIM pim = null;
    //private PIMItem searchTerm = null;
    Form form;


    public void cleanup() {
    tp = null;
    }

    public String getName() {
    return "Globe G2";
    }

    protected void executeDemo(Container f)
    {
    f.setLayout(new BorderLayout());
    f.setScrollable(false);
    tp = new Tabs();

    //contact list tab
    Container ContactListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    ContactListPanel.setScrollableY(true);


    System.out.println("Contacts tab ito");
    contactList = new com.sun.lwuit.List();
    pim = PIM.getInstance();

    System.out.println("populate contact list");
    contactList.setModel(new DefaultListModel());
    System.out.println("populate contact list1");


    try
    {
    String[] pimListNames = pim.listPIMLists(PIM.CONTACT_LIST);

    for (int i = 0; i < pimListNames.length; ++i)
    {
    ContactList cl = (ContactList) pim.openPIMList(
    PIM.CONTACT_LIST, PIM.READ_ONLY, pimListNames[i]);
    Enumeration items = cl.items();

    while (items.hasMoreElements())
    {
    Contact c = (Contact) items.nextElement();

    String[] nameArray = null;

    if (c.countValues(Contact.NAME) > 0)
    {
    nameArray = c.getStringArray(Contact.NAME, 0);
    }

    if (nameArray != null)
    {
    for (int j = 0; j < nameArray.length; j++)
    {
    if (nameArray[j] != null)
    {
    (contactList).addItem(nameArray[j]);
    break;
    }
    }
    }
    }
    }
    }
    catch (PIMException ex)
    {
    ex.printStackTrace();
    }

    form.revalidate();

    final TextArea searchField = TextField.create();

    Button searchButton = new Button("Search");

    searchButton.addActionListener(new ActionListener()
    {

    public void actionPerformed(ActionEvent evt)
    {
    populateContactList(searchField.getText());
    }
    });
    Button clearButton = new Button("Clear");
    clearButton.addActionListener(new ActionListener()
    {

    public void actionPerformed(ActionEvent evt)
    {
    populateContactList("");
    }
    });

    populateContactList(searchField.getText());

    //ContactListPanel.show();

    //ContactListPanel.addComponent(searchField);
    //ContactListPanel.addComponent(searchButton);
    //ContactListPanel.addComponent(clearButton);

    ContactListPanel.addComponent(contactList);

    /****sample content starts here*/

    /* System.out.println("Contact Tabs");
    RadioButton rb;
    ButtonGroup group = new ButtonGroup();

    rb = new RadioButton("Cean Bravo");
    group.add(rb);
    ContactListPanel.addComponent(rb);

    rb = new RadioButton("Chen Sy");
    group.add(rb);
    ContactListPanel.addComponent(rb);

    rb = new RadioButton("Jane Doe");
    group.add(rb);
    ContactListPanel.addComponent(rb);

    rb = new RadioButton("John Doe");
    group.add(rb);
    ContactListPanel.addComponent(rb);

    rb = new RadioButton("Shane Amog");
    group.add(rb);
    ContactListPanel.addComponent(rb);
    */
    ContactListPanel.setScrollableY(true);
    //ContactBookDemo();
    tp.addTab("Contacts", ContactListPanel);
    /****sample content ends here*/

    ///////////////////////////////////////////////////////////////////////////////////

    //message tab
    Container MessageListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    MessageListPanel.setScrollableY(true);

    System.out.println("Messages tab ito");
    Form mform = new Form();

    //message sending form
    TextArea number = new TextArea(1, 11, TextArea.PHONENUMBER);
    number.setMaxSize(11);
    TextArea message = new TextArea(4, 160, TextArea.ANY);
    message.setMaxSize(160);
    final Button sendbtn = new Button("Send");



    //alert box
    alertsend = new Alert("Message Successfully send");
    alertsend.setTimeout(5000);
    alertsend.setType(AlertType.CONFIRMATION);

    final Command command1 = new Command("OK");
    final Command command2 = new Command("Exit");

    mform.addCommand(command1);
    mform.addCommand(command2);

    Label lbl = new Label("Type your message...");
    lbl.setFocusable(true);
    lbl.setUIID("TitleLabel");
    MessageListPanel.addComponent(lbl);
    MessageListPanel.addComponent(number);
    MessageListPanel.addComponent(message);
    MessageListPanel.addComponent(sendbtn);
    MessageListPanel.addComponent(mform);

    tp.addTab("Messages", MessageListPanel);
    f.addComponent("Center", tp);



    }


    protected void populateContactList(String string) {

    }

    protected void destroyApp(boolean unconditional)
    throws MIDletStateChangeException {

    }

    protected void pauseApp() {

    }

    protected void startApp() throws MIDletStateChangeException {

    }


    }


    Thanks! can you help me debug it?

  12. #12
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    Again your startapp seems to be empty .You are not extending the MIDlet class either.You have to do that if you want to create a S40 App.

    What does your Demo class contain?

    In execute demo, the first line says

    f.setLayout(new BorderLayout());

    But I cant find the variable called f being declared or initialised anywhere.

  13. #13
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    the reason why it is not on this midlet because the code is in other class.
    There are other supporting class for this midlet to work and it doesnt seems to generate error.
    i am still wondering why the contact list is not showing.

  14. #14
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    272

    Re: PIM Contact List inside LWUIT Tab

    Okay...I suspect that the variable f is the culprit.Kindly check whether it is properly initialized.

  15. #15
    Registered User
    Join Date
    Apr 2014
    Posts
    8

    Re: PIM Contact List inside LWUIT Tab

    If I figure it out! But it is not the variable f making the error. thanks!

Similar Threads

  1. LWUIT list scrolling is slow whenever list cells contain long strings
    By lordbritishix1982 in forum Mobile Java UI and User Experience
    Replies: 1
    Last Post: 2013-12-03, 19:08
  2. Add list after showing form (hack for lwuit s40 list bug)
    By xuanphung001 in forum Mobile Java General
    Replies: 2
    Last Post: 2013-04-24, 03:15
  3. How to append LWUIT List screen to a LWUIT Form in j2me?
    By pavanragi in forum Mobile Java General
    Replies: 1
    Last Post: 2012-08-06, 07:01
  4. How to create a combobox inside Lwuit Table
    By neerajj50@gmail.com in forum Mobile Java General
    Replies: 2
    Last Post: 2011-05-18, 06:05
  5. cannot add new contact list in my contact list application
    By dexth in forum Mobile Java General
    Replies: 0
    Last Post: 2009-10-10, 12:31

Posting Permissions

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