[Pytanie] - J2ME - Program nic nie wyświetla na ekranie

Odpowiedz Nowy wątek
axes666
2010-01-10 18:14
axes666
0

Witam bardzo serdecznie, mam pewien kodzik:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ADiN
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
import java.util.*;

public class Pierwsza extends MIDlet implements CommandListener{
//Forms
    Form myForm;
    Form newContactForm;
//Text Fields
    TextField enterName;
    TextField enterNick;
    TextField enterNumber;
//Display object
    Display display;
//ContactList
    ContactList myContactList = null;
//Enumeration object for storing contacts in
    Enumeration contact;
//Contact
    Contact c = null;
//Commands
    Command contactDB;
    Command displayPhonebook;
    Command enterContact; //Take to contact input form
    Command addContact; //Commit contact to DB
    Command showFields;
    Command showFieldAttributes;
    Command showCategories;
    Command clearScreen;
//PIMS
    PIM myPIM;

    public Pierwsza(){

    }

    private void initPIM(){
        myForm.deleteAll();
        myPIM = PIM.getInstance();
        try {
            String ContactList[] = myPIM.listPIMLists(PIM.CONTACT_LIST);
            myContactList = (ContactList) myPIM.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
            contact = myContactList.items();
        }

        catch (Exception e) {
            e.printStackTrace();
        }
        DisplayContacts();
    }

    void DisplayNewContactForm(){
        newContactForm = new Form("Enter new contact");
        addContact = new Command("Add", Command.OK, 0);
        enterName = new TextField("Enter Name","", 20, TextField.ANY);
        enterNick = new TextField("Enter Nick","", 20, TextField.ANY);
        enterNumber = new TextField("Enter Tel","", 20, TextField.ANY);
        newContactForm.append(enterName);
        newContactForm.append(enterNick);
        newContactForm.append(enterNumber);
        newContactForm.addCommand(addContact);
        newContactForm.addCommand(displayPhonebook);
        newContactForm.setCommandListener(this);
        display.setCurrent(newContactForm);
    }

    void createNewContact(){
        String getName = enterName.getString();
        String getNick = enterNick.getString();
        String getNumber = enterNumber.getString();
        Contact newContact = myContactList.createContact();
//Name
        if (myContactList.isSupportedField(Contact.FORMATTED_NAME)){
            try{
                newContact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, getName);
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
        else{
            System.out.println("THIS IS NAME");
        }
//NickName
        if (myContactList.isSupportedField(Contact.NICKNAME)){
            try{
                newContact.addString(Contact.NICKNAME, Contact.ATTR_MOBILE, getNick);
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
//Telephone
        if (myContactList.isSupportedField(Contact.TEL)){
            try{
                newContact.addString(Contact.TEL, PIMItem.ATTR_NONE, getNumber);
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
        try{
//write the new Contact to the PIM database
            newContact.commit();
            System.out.println("Contact Added \n");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    void displayContactListFields(){
        int[] arrayFields = myContactList.getSupportedFields();
        myForm.append("Supported Fields \n");
        for(int i = 0; i < arrayFields.length ; i++){
            try{
                myForm.append(myContactList.getFieldLabel(arrayFields[i]) + "\n");
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
    }

    void displayContactListCategories(){
        try{
            String[] listCategories = myContactList.getCategories();
            myForm.append("Supported Categories");
            for(int i = 0; i < listCategories.length ; i++){
                myForm.append(listCategories[i] + "\n");
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    void displayFieldAttributes(){
        int[] arrayFields = myContactList.getSupportedFields();
        for(int i = 0; i < arrayFields.length ; i++){
            try{
                myForm.append("\n" + myContactList.getFieldLabel(arrayFields[i]) + " : ");
                int attrList[] = myContactList.getSupportedAttributes(arrayFields[i]);
                for(int j=0;j<attrList.length;j++){
                    myForm.append(myContactList.getAttributeLabel(attrList[j]) + " ");
                }
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
    }

    void DisplayContacts(){
        while (contact.hasMoreElements()) {
            c = (Contact) contact.nextElement();
            int[] Fields = c.getFields();
            String[] catArray = c.getCategories();
            for(int ii = 0; ii < catArray.length ; ii++){
                myForm.append("Category :" + catArray[ii] + "\n");
            }
            for(int i = 0; i < Fields.length ; i++){
                String field = myContactList.getFieldLabel(Fields[i]);
                if(Fields[i] == Contact.FORMATTED_NAME){
                    myForm.append("Name : " + c.getString(Fields[i],0) + "\n");
                }
                if(Fields[i] == Contact.TEL){
                    int att = c.getAttributes(Fields[i],0);
                    String attributeLabel = myContactList.getAttributeLabel(att);
                    if(attributeLabel.compareTo("NONE") < 0){
                        myForm.append(attributeLabel + " : " + c.getString(Fields[i],0) + "\n");
                    }
                    else{
                        myForm.append("Telephone : "+ c.getString(Fields[i],0) + "\n");
                    }
                }
            }
        }
    }
    public void startApp() {

        myForm = new Form("Contact PIM");
        display = Display.getDisplay(this);
        displayPhonebook = new Command("PhoneBook",Command.OK, 0);
        enterContact = new Command("EnterContact",Command.OK, 0);
        showFields = new Command("Fields",Command.OK, 0);
        showFieldAttributes = new Command("Attributes",Command.OK, 0);
        showCategories = new Command("Categories",Command.OK, 0);
        clearScreen = new Command("Clear Screen",Command.OK, 0);

        myForm.addCommand(displayPhonebook);
        myForm.addCommand(enterContact);
        myForm.addCommand(showFields);
        myForm.addCommand(showFieldAttributes);
        myForm.addCommand(showCategories);
        myForm.addCommand(clearScreen);
        myForm.setCommandListener(this);

        display.setCurrent(myForm);
        myPIM = PIM.getInstance();
        initPIM();
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable d) {
        if(c == displayPhonebook){
            initPIM();
            display.setCurrent(myForm);
        }
        else
            if(c == enterContact){
                DisplayNewContactForm();
            }
            else
                if(c == addContact){
                    createNewContact();
                    DisplayNewContactForm();
                }
                else
                    if (c == showFields){
                        displayContactListFields();
                    }
                    else
                        if(c == showFieldAttributes){
                            displayFieldAttributes();
                        }
                        else
                            if(c == showCategories){
                                displayContactListCategories();
                            }
                            else
                                if(c == clearScreen){
                                    myForm.deleteAll();
                                }
    }
}

I problem polega na tym, że na ekranie telefonu nie wyświetla mi się w sumie nic Był bym wdzięczny jak by ktoś na to rzucił okiem i ewentualnie powiedział czemu się tak dzieje. Zapewne problem tkwi w metodzie startApp(), z tym że nie jestem wstanie wyłapać czemu programik nie rusza. Istnieje też możliwość, że metody są pomieszane za bardzo i program gdy wystartuje rozpoczyna pracę od złej metody.

Pozdrawiam

P.S. Korzystam ze środowiska Java(TM) ME Platform SDK 3.0

Pozostało 580 znaków

abe
2010-01-11 18:21
abe

Rejestracja: 11 lat temu

Ostatnio: 4 lata temu

0

U mnie dziala

Pozostało 580 znaków

Odpowiedz

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0