2011-09-22 91 views
0

卡住了MessageList中我嘗試做將MessageList在黑莓使用的MIDlet,但無論我做一些厚望出現。現在我得到NullPointerException。下面是代碼在黑莓

EncodedImage indicatorIcon = EncodedImage.getEncodedImageResource("img/indicator.png"); 
    ApplicationIcon applicationIcon = new ApplicationIcon(indicatorIcon); 
    ApplicationIndicatorRegistry.getInstance().register(applicationIcon, false, false); 

    ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance(); 
    MessageListStore messageStore = MessageListStore.getInstance(); 
    if(reg.getApplicationFolder(INBOX_FOLDER_ID) == null) 
    { 
     ApplicationDescriptor daemonDescr = ApplicationDescriptor.currentApplicationDescriptor(); 
     String APPLICATION_NAME = "TestAPP"; 
     ApplicationDescriptor mainDescr = new ApplicationDescriptor(daemonDescr, APPLICATION_NAME, new String[] {}); 
     ApplicationFolderIntegrationConfig inboxIntegration = new ApplicationFolderIntegrationConfig(true, true, mainDescr); 
     ApplicationFolderIntegrationConfig deletedIntegration = new ApplicationFolderIntegrationConfig(false); 

     ApplicationMessageFolder inbox = reg.registerFolder(MyApp.INBOX_FOLDER_ID, "Inbox", messageStore.getInboxMessages(), 
         inboxIntegration); 
     ApplicationMessageFolder deleted = reg.registerFolder(MyApp.DELETED_FOLDER_ID, "Deleted Messages", messageStore.getDeletedMessages(), deletedIntegration); 
     messageStore.setFolders(inbox, deleted); 
    } 
    DemoMessage message = new DemoMessage(); 
    String name = "John"; 
    message.setSender(name); 
    message.setSubject("Hello from " + name); 
    message.setMessage("Hello Chris. This is " + name + ". How are you? Hope to see you at the conference!"); 
    message.setReceivedTime(System.currentTimeMillis()); 
    messageStore.addInboxMessage(message); 
    messageStore.getInboxFolder().fireElementAdded(message); 

有人建議我一個簡單的將MessageList樣品的MIDlet只是顯示字符串將MessageList和定製ApplicationIndicator值。如果可能,OnClick of消息從後臺返回midlet。

回答

2

使用下面的代碼:

static class OpenContextMenu extends ApplicationMenuItem { 
     public OpenContextMenu(int order) { 
      super(order); 
     } 

     public Object run(Object context) { 
      if(context instanceof NewMessage) { 
       try { 
        NewMessage message = (NewMessage) context; 
        if(message.isNew()) { 
         message.markRead(); 
         ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance(); 
         ApplicationMessageFolder folder = reg.getApplicationFolder(Mes 

sageList.INBOX_FOLDER_ID); 
        folder.fireElementUpdated(message, message); 
        //changeIndicator(-1); 
       } 

       Inbox inbox = message.getInbox(); 
       Template template = inbox.getTemplate(); 

       //Launch the mainscreen 
       UiApplication.getUiApplication().requestForeground(); 
      } 
      catch (Exception ex) { 
       Dialog.alert(); 
      } 
     } 
     return context; 
    } 

    public String toString() { 
     return "Name of the menu item"; 
    } 
} 
+0

使用此人?我想爲這個代碼中的Midlet給它UiApplication.getUiApplication()。requestForeground(); – aNi

+0

我從來沒有使用這樣的代碼爲midlets。但我不認爲它會有所不同 –

+0

謝謝......它工作 – aNi