BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-13-2008, 05:50 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Global variable?

Please Login to Remove!

hi there,
i have a class which should be availeble an all screens in my project, including the email event.

i have implementet the email listener to my mainscreen. now i get an email an call a void. in this void a new instance of my class should be build and add to my vector. after that a listfiled should be updated with the data of my vector. the "problem" is, that the listfield is on an other screen as the voids which work with the data.

her is some code, maybe you understand my problem and can help me ;)
PHP Code:
//maiscreen:
public static clsData allData null;

public 
void messagesAdded(FolderEvent e) {
        
Message m e.getMessage();     
        
String subject =m.getSubject();
        
String body m.getBodyText();
        
addToVector(subject,body);   
    }
public 
void addToVector(String _subjectString _body) {
    try {
        
synchronized(this) {
            
clsItem newItem = new clsItem();
            
Stringxxx91;xxx93; data split(_subject,":");
            
long ID Long.parseLong(dataxxx91;0xxx93;);
            
newItem.setBodyText(_body);
            
newItem.setStatusText("Test");
            
newItem.setID(ID);
            if (
allData == null) {
                
System.out.println("erzeuge allData neu");
                
allData = new clsData();
            }
            
allData.addAuftrag(newAuftrag); 
            
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
                public 
void run() {
                   
anotherScreen.getList(); 
                }
            });
        }  
    } catch (
Exception ex) {Dialog.alert("Error 0x149: "+ex.toString());}
}

//anotherScreen
 
public void getPatList() {
// add to list
//this void works, i have testet it

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 11-13-2008, 08:11 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm, i am not really able to follow your workflow.
you have an email-listener implemented in your application and want to add all subject/body-strings into a list?

i would suggest that you put some order into your control structure first.

create a class, lets call it Store, that registers itself as a FolderListener.
In this class you do your mumbo-jumbo.
create a method addStoreListener that adds a StoreListener (an interface).
publish this method using an interface StoreService.

your screen is created with the storeservice as an argument and implements StoreListener.
in the constructor the screen adds itself as a listener to the store.
when the mumbo-jumbo is complete the store iterates through all storelisteners and calls the method dataIsHere(Vector data).

in your screen you can add data to an ObjectListField.

before doing this: grab yourself a sheet of paper (or an UML editor :D ) and draw the whole thing.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 11-24-2008, 03:56 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
sry for replying so late. i have tried to solve the problem this way, but now i've got a new problem. but first here is my code, i hope you understand what i have done ^^

here is the class with the email listener:
PHP Code:
public class clsStore implements FolderListener {
    private 
Vector _messages;
    private 
Service _service;   
    private 
frmAuftrage _screen
    private 
ListField _c;
    private 
frmAuftrage.ListCallback _callback;
    
public 
void messagesAdded(FolderEvent e) {
    try {
        
System.out.println("Neue email eingegangen");
        
Message m e.getMessage();     
        
String subject =m.getSubject();
        
String body m.getBodyText();
        
clsAuftrag myAuftrag = new clsAuftrag();
        
        
myAuftrag.setBodyText(body);
        
myAuftrag.setID(1234);
        
        
_messages.addElement(myAuftrag);
        } catch (
Exception ex) { System.out.println("Error 0x1145: " ex.toString());}
        
        
_screen.setListe(_messages,_c,_callback);
    
}
    
public 
void messagesRemoved(FolderEvent e) {}

clsStore(frmAuftrage mainScreen,ListField listefrmAuftrage.ListCallback clBack ) {
        
_messages = new Vector();
        
_screen mainScreen;
        
_c liste;
        
_callback clBack;
        try { 
_service Session.waitForDefaultSession().getStore();} catch (Exception ex) {}        
        final 
Store store = (Store)_service;
        
store.addFolderListener(this);
}

then i have the class, wher the listfield is shown:
PHP Code:
public class frmAuftrage extends MainScreen {
     
    public static 
Vector auftragsListe = new Vector();
    
    public static 
ListField c;
    public static 
ListCallback callback;
    private 
clsStore store;

 public 
frmAuftrage() {                 
      
// ...       
        
= new ListField();     
        
callback = new ListCallback();
        
c.setCallback(callback);
        
add(c);
        
        
store = new clsStore(this,c,callback); // callback is a own class to paint the listField 
then there is the void setListe(), which should update the listField (this void is in the class frmAuftrage :
PHP Code:
public void setListe(Vector _listListField _cListCallback _callback) {
      
auftragsListe = new Vector(); 
      
auftragsListe _list;
      
_c;
      
callback _callback;
      
System.out.println("größe von _list: " _list.size());
      
UiApplication.getUiApplication().invokeLater(new Runnable(){
        public 
void run(){
                 try {
                    
clsAuftrag pat null;
                    
// liste leeren
                    
while(c.getSize() > 0) {
                            
c.delete(0);
                            
callback.listElements.removeElementAt(0);
                    } 
//*/
                    
                    
System.out.println("größe von auftragsListe: " auftragsListe.size());
                    
c.insert(0);
                    
callback.insert("Neu Bla bla blubb",0);
                    
                    for(
int i 0auftragsListe.size(); i++) {
                        
pat = (clsAuftrag)auftragsListe.elementAt(i);
                        
c.insert(i);//vorher immer 0 nikolaus
                        
callback.insert(pat.getStatusText(),i); // vorher 0 = i
                        
c.invalidate();
                    }
                } catch (
Exception ex) {System.out.println("Error 0x148: "+ex.toString());}
                }
       });
    } 
Now the exception with the error 0x148 is thrown:
Quote:
Neue email eingegangen
größe von _list: 1
größe von auftragsListe: 1
Error 0x148: java.lang.IllegalStateException: UI engine accessed without holding the event lock.
why is the exception thrown out?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 11-24-2008, 08:13 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

java.lang.IllegalStateException: UI engine accessed without holding the event lock

this does usually mean that you do not hold the event lock.
use invokelater or synchronize on getEventlock of UiApplication.
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.