Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
simon_hain
Posts: 15,805
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: App crashing when accessing email attachment...

just to get it a little bit quicker: you can use javaloader to load applications using the command line, it's probably a lot quicker than using the BES in between.
you find it in the vmtools folder of your eclipse plugin.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
jgobert
Posts: 22
Registered: ‎08-22-2012
My Device: Bold 9900
My Carrier: Verizon Wireless

Re: App crashing when accessing email attachment...

Ok here are three parts for you... I reinstalled the app and pushed an email message to it.  I took a screenshot of the error log showing the events and then copied the full text of each event and pasted below.

 

*****************************************************************
Name: PrecisionCollector
GUID: 3401882cc7a5a956
Time: Aug 22, 2012 11:24:17
Exception caugth in PrecicionMessage.run(): java.lang.Exception: Could not obtain attachment from Precision Message

Log:

*****************************************************************
Name: ControlledAccessException
GUID: 9c3cd62e3320b498
Time: Aug 22, 2012 11:24:17
Unauthorized attempt to attach to this application
net_rim_cldc-10(4EDC0D64)
 Application
 getApplication
 0x3C1D
net_rim_bbapi_mailv2(4EDC1314)
 Session
 isMailServiceAccessible
 0x6391
net_rim_bbapi_mailv2(4EDC1314)
 Session
 isMailServiceAccessible
 0x63F8
net_rim_bbapi_mailv2(4EDC1314)
 Session
 assertPersonalLiabilityPermssion
 0x61CA
net_rim_bbapi_mailv2(4EDC1314)
 Session
 getInstance
 0x6272
net_rim_bbapi_mailv2(4EDC1314)
 Folder
 <init>
 0x2088
net_rim_bbapi_mailv2(4EDC1314)
 Folder
 <init>
 0x2021
net_rim_bbapi_mailv2(4EDC1314)
 ListenerManager
 doDispatch
 0x2D99
net_rim_bbapi_mailv2(4EDC1314)
 ListenerManager
 dispatchFolderEvent
 0x2E9A
net_rim_bbapi_mailv2(4EDC1314)
 ListenerManager
 elementRemoved
 0x2800
net_rim_cldc-5(4EDC0D64)
 CollectionListenerManager
 fireElementRemoved
 0x2EF4
net_rim_bb_messaging(4EDC0DEE)
 MergedCollection
 elementRemoved
 0x3EC3
net_rim_cldc-5(4EDC0D64)
 CollectionListenerManager
 fireElementRemoved
 0x2EF4
net_rim_bb_messaging-2(4EDC0DEE)
 SortedCollection
 remove
 0x2930
net_rim_bb_messaging-2(4EDC0DEE)
 PersistedSortedCollection
 remove
 0x21EA
net_rim_bb_email-8(4EDC12E7)
 PersistedSortedCollectionHook
 remove
 0x5EE2
net_rim_bb_messaging-2(4EDC0DEE)
 SortedCollection
 remove
 0x2BE4
net_rim_bb_email(4EDC12E7)
 EmailMessageModelImpl
 delete
 0x90BD
net_rim_bb_email(4EDC12E7)
 EmailMessageModelImpl
 delete
 0x873E
net_rim_bb_email(4EDC12E7)
 EmailMessageModelImpl
 perform
 0x52E8
net_rim_bbapi_mailv2(4EDC1314)
 Folder
 deleteMessage
 0x1D6B
PrecisionCollector(503500F3)
 IncomingMail
 messagesAdded
 0x4E88
net_rim_bbapi_mailv2-1(4EDC1314)
 FolderEvent
 dispatch
 0x63
net_rim_bbapi_mailv2(4EDC1314)
 ListenerManager$AsyncFolderListener$Callback
 execute
 0x33AB
net_rim_cldc-7(4EDC0D64)
 ExternalListener$SynchronizedCallback
 run
 0x372E
net_rim_cldc-7(4EDC0D64)
 ProxyRunnableQueue
 run
 0xB58F
net_rim_cldc-2(4EDC0D64)
 Thread
 run
 0xAAC9

 

9900 Error Log

Please use plain text.
Contributor
jgobert
Posts: 22
Registered: ‎08-22-2012
My Device: Bold 9900
My Carrier: Verizon Wireless

Re: App crashing when accessing email attachment...

I just finished up writing an email to RIM's dev support folks... I've never worked with them so I'm crossing my fingers that they can help.  I included a zip file with the source, workspace folder, the screenshot I posted earlier and two text files with the full text of the two event log entries... I tried to give a good breakdown of what the app should be doing vs what it is doing and some history on it.  I hope that's everything they need... 

 

I'm gonna keep working on it though... hopefully one of these avenues will do the trick :smileyhappy: 

 

I can't thank you guys enough for looking at this with me... considering this was my first post here I was worried that folks wouldn't be too friendly but you definitely proved that to be false. 

 

If you happen to come up with any other ideas please let me know... otherwise, again, thank you very much for your help!

Please use plain text.
Administrator
MSohm
Posts: 14,229
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: App crashing when accessing email attachment...

Peter has you going down the right path in regards to moving code out of the listener and into your application.

 

Basically you are trying to do something in the listener in which the process running the listener does not have permission to do, thus triggering a ControlledAccessException.

 

Have you stepped through the code to see what line of code is triggering it?  That'll help you with first steps for code to move out into your own application process.  But ideally, the listener does minimal work and just fires off and update alert with data to your application, which does all of the processing.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Contributor
jgobert
Posts: 22
Registered: ‎08-22-2012
My Device: Bold 9900
My Carrier: Verizon Wireless

Re: App crashing when accessing email attachment...

I'm trying my best to narrow it down as much as possible... my biggest issue is that I don't know if I have the chops needed to rewrite the necessary code.  I'm familiar enough with programming in general to effectively troubleshoot and with enough time and resources make corrections or updates where needed.  I'm kinda stuck with a deadline on this that totally wipes out any chance of having the time to learn enough about writing Blackberry code to make this happen.  The company bought over 100 new Bold 9900 / 9930's to refresh the fleet but without this app working we have to cancel everything within the initial 30-day window... that's closing fast on me.  My marching orders are to make it work or scrub Blackberry all together in favor of iPhone.  We've been vested in Blackberry for many years now and I have absolutely no want to have to deal with an entire platform change on top of everything else we have going on right now...  Ok... sorry for venting there... just really frustrated...

 

Aside from all of this I did send everything in to RIM today and paid for a dev support incident.  Based on your knowledge of how all of this works will they be able / willing to help me fix this?  I'm not 100% on what all they'll do to assist but I figured it couldn't hurt to at least pay for it and try.

 

Thoughts?

Please use plain text.
Developer
simon_hain
Posts: 15,805
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: App crashing when accessing email attachment...

to move the code out of your listener you do the following:

1. in your main application, register a global event listener
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/Application.html#addGlo...

2. in your mail listener, you post a global event with a GUID you set
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/ApplicationManager.html... long, int, int, java.lang.Object, java.lang.Object)
(there are different methods, but this one allows you to add the message object)

3. depending on the processing needs of the code you process the message from the event received method or spawn a new thread to handle it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
jgobert
Posts: 22
Registered: ‎08-22-2012
My Device: Bold 9900
My Carrier: Verizon Wireless

Re: App crashing when accessing email attachment...

Thank you for the references.  I'm walking through the app step by step to make sure I see how each part comes together.  I wanted to share the following code... If I'm not mistaken it's the starting point for the application.

 

import java.util.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import javax.microedition.rms.*;
import net.rim.blackberry.api.mail.*;

class PrecisionCollector extends UiApplication implements GlobalEventListener
{
    Thread PrecisionMsgThread = null;
    Vector PrecisionMsgVector = new Vector();
    
    public static void main(String args[])
    {

        if ( args != null && args.length > 0 && args[0].equals("gui") )
        {
            PrecisionGUI theApp = new PrecisionGUI();
            theApp.enterEventDispatcher();
        }
        else
        {
            PrecisionCollector theThread = new PrecisionCollector();
            theThread.enterEventDispatcher();
        }
    }

    public PrecisionCollector()
    {
        try
        {
            // Register the Precision Collector with the Event Logger
            EventLogger.register(0x3401882cc7a5a956L, "PrecisionCollector", EventLogger.VIEWER_STRING);
            
            // Version the Record Stores and Persistent Stores
            PersistentObject _DBVersionStore = PersistentStore.getPersistentObject(0x6abc2f4adee24c9eL); // DBVersion
            DBVersion _DBVersion = (DBVersion)_DBVersionStore.getContents();
            
            if(_DBVersion == null)
            {
                _DBVersion = new DBVersion();
                _DBVersion.DBVersion = DataStore._DBVersion;
                _DBVersionStore.setContents(_DBVersion);
                _DBVersionStore.commit();
            }
            else if(!_DBVersion.DBVersion.equals(DataStore._DBVersion))
            {
                RecordStore.deleteRecordStore("PrecisionLocations");
                RecordStore.deleteRecordStore("PrecisionEquipment");
                RecordStore.deleteRecordStore("PrecisionMeters");
                RecordStore.deleteRecordStore("PrecisionReasonsNotCollected");
                RecordStore.deleteRecordStore("PrecisionMeterTypes");

                _DBVersion.DBVersion = DataStore._DBVersion;
                _DBVersionStore.setContents(_DBVersion);
                _DBVersionStore.commit();
            }
        }
        catch(Exception exception)
        {
            EventLogger.logEvent(0x3401882cc7a5a956L, ("Exception caught in PrecisionCollector Constructor: " + exception.toString()).getBytes(), EventLogger.SEVERE_ERROR);
            exception.printStackTrace();
        }
        
        DataStore.Initialize();
        
        // Set the Server Update (POST close location messages) to be performed hourly
        new Timer().scheduleAtFixedRate(new ServerConnect(), 600000, 600000);
        addGlobalEventListener(this);
        IncomingMail incomingMail = new IncomingMail();
    }

    public void eventOccurred( long guid, int data0, int data1, Object object0, Object object1)
    {
        if (guid == 0x5c8e492bc9269b0cL)
        {
            Message EmailMsg = (Message)object0;

            EventLogger.logEvent(0x3401882cc7a5a956L, "Received Precision Message Global Event PrecisionCollector.eventOccured()".getBytes(), EventLogger.DEBUG_INFO);
            PrecisionMsgVector.addElement(EmailMsg);
            ProcessPrecisionMsg(false);
        }
    }

    public void ProcessPrecisionMsg(boolean force)
    {
        if(PrecisionMsgVector.isEmpty())
        {
            PrecisionMsgThread = null;
            return;
        }
        else if(force || PrecisionMsgThread == null || !PrecisionMsgThread.isAlive())
        {
            Message EmailMsg = ((Message)PrecisionMsgVector.firstElement());
            PrecisionMsgVector.removeElement(EmailMsg);
                   
            PrecisionMsgThread = new Thread(new PrecisionMessage(EmailMsg, this));
            PrecisionMsgThread.setPriority(Thread.MIN_PRIORITY);
            PrecisionMsgThread.start();
        }
    }
}

class DBVersion implements Persistable
{
    public String DBVersion;
}

 

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: App crashing when accessing email attachment...

Looks like that too me too.  Do you have a question?

 

The interesting thing is that this code actually already sets up a GlobalEventListener.

 

The next bit of code you really want to find is the Listener - I suspect it is in the IncomingMail class. 

Please use plain text.
Contributor
jgobert
Posts: 22
Registered: ‎08-22-2012
My Device: Bold 9900
My Carrier: Verizon Wireless

Re: App crashing when accessing email attachment...

Sorry I fell asleep at my keyboard again last night after posting that code... As I track through the code I'm trying to post here so hopefully you may see something I'm missing.  Here's the IncomingMail.java code:

 

import net.rim.device.api.system.*;
import net.rim.blackberry.api.mail.*;
import net.rim.blackberry.api.mail.event.*;
import net.rim.device.api.system.ApplicationManager;

public final class IncomingMail implements FolderListener
{
    IncomingMail()
    {
        try
        {
            Session.getDefaultInstance().getStore().addFolderListener(this);
            AttachmentHandlerManager.getInstance().addAttachmentHandler(new PrecisionAttachment());
        }
        catch (Exception e)
        {
            EventLogger.logEvent(0x3401882cc7a5a956L, ("Exception caught in IncomingMail Constructor: " + e.toString()).getBytes(), EventLogger.SEVERE_ERROR);
            e.printStackTrace();
        }
    }
     
    public void messagesAdded(FolderEvent event)
    {
        Message message = event.getMessage();
        Folder messageFolder = message.getFolder();
        
        System.out.println("MEssage folder: " + messageFolder.getType());
        
        if (messageFolder.getType() == Folder.INBOX && message.getSubject() != null && message.getSubject().trim().equals( "PrecisionMessage {8E730E0B-F94C-4e88-858C-20910B31C4C3}")) 
        {
            System.out.println("Received Precision Message!!!");
            // [DNT] 09/26/09 - Item#1.5
            message.setFlags(Message.Flag.OPENED);
            //message.setFlags(Message.Flag.OPENED | Message.Flag.DELETED);
            messageFolder.deleteMessage(message); 

            ApplicationManager.getApplicationManager().postGlobalEvent(0x5c8e492bc9269b0cL, 0, 0, message, null);  // ParseMessage
        }
    }

    public void messagesRemoved(FolderEvent event)
    {}
}

 

Please use plain text.
Contributor
jgobert
Posts: 22
Registered: ‎08-22-2012
My Device: Bold 9900
My Carrier: Verizon Wireless

Re: App crashing when accessing email attachment...

Continuing from the previous post, the code below is for PrecisionAttachment.java which is called in the IncomingMail() try block....

 

import net.rim.blackberry.api.mail.*;

class PrecisionAttachment implements AttachmentHandler
{
    public String menuString()
    {
        return "Viewing Not Supported";
    }
    
    public void run(Message m, SupportedAttachmentPart p)
    { }
    
    public boolean supports(String contentType)
    {
        return (contentType.toLowerCase().indexOf("x-rimdevice-precisionmessage") == -1 ? false : true);
    }
}

 

Please use plain text.