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
New Contributor
Posts: 7
Registered: ‎03-18-2010
My Device: 8300
My Carrier: student

I get uncaught throwable. Any help would be appreciated

 

class TestMenuItem extends ApplicationMenuItem

{

    .................

public Object run(Object context) {

MessageConnection mconn;
  TextMessage textmessage = null;
  try {
   mconn = (MessageConnection)Connector.open("sms://1234567890");
   textmessage = (TextMessage) mconn
         .newMessage(MessageConnection.TEXT_MESSAGE);
   textmessage.setAddress("sms://1234567890");
       textmessage.setPayloadText("dasdasdasd");
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   return null;
  }

Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(textmessage) );

}

}

 

I added a menuitem to Calendar application. After I click the menuitem, I sended the message. But uncaught throwable appeared.

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: I get uncaught throwable. Any help would be appreciated

It looks like you are doing the sms messaging within the run method. That method is called in the event thread, and it should not be used for time-consuming operations. You need to use the run method to start a separate thread to do the work. The RIM video What is the Event Thread? is a good introduction to this.

 

It also might help to know what the throwable was.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: I get uncaught throwable. Any help would be appreciated

I agree with Ted,

 

Also if you change:

 

  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   return null;
  }

 

to

  } catch (Throwable t) {
   // TODO Auto-generated catch block
   t.printStackTrace();
   return null;
  }

 

you will catch the Throwable. 

New Contributor
Posts: 7
Registered: ‎03-18-2010
My Device: 8300
My Carrier: student

Re: I get uncaught throwable. Any help would be appreciated

MessageConnection mconn;

TextMessage textmessage;

class ConnectionThread extends Thread
 {
  boolean end;
  public ConnectionThread()
  {
   end = false;
  }
  public boolean getEnd()
  {
   return end;
  }
  public void run()
  {
   try {
    mconn = (MessageConnection)Connector.open("sms://1234567890");
    textmessage = (TextMessage) mconn
          .newMessage(MessageConnection.TEXT_MESSAGE);
    textmessage.setAddress("sms://1234567890");
        textmessage.setPayloadText("dasdasdasd");
        mconn.close();
        end = true;
   } catch (Throwable e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }

 

public Object run(Object context) {

ConnectionThread thread = new ConnectionThread();
  thread.start();
  while(true)
  {
   if(thread.getEnd())
   {
    Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(textmessage) );
    break;
   }
  }
  
  return context;
 }

 

I still got uncaught throwable,when I clicked "quit" in the outbox.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: I get uncaught throwable. Any help would be appreciated

If you are clicking QUIT, then you are running on the Event Thread, in which case it seems unlikely that you are processing within this Thread. 

 

You could use EventLogger to track the progress of your processing and try to determine exactly where it is before this exception is thrown. 

 

Also if the Exception is not thrown, the BlackBerry VM will dump out a stack trace for you, so the Event log should tell you where the Exception is being thrown.  Can you get the Stack Trace for this Exception?

New Contributor
Posts: 7
Registered: ‎03-18-2010
My Device: 8300
My Carrier: student

Re: I get uncaught throwable. Any help would be appreciated

[ Edited ]

Thank you for your help. But I don't know how to view the event log.

what I know is that from the Tools menu, click Show Event Log.   How can I get the stack trace?

 

whole code:

 

import java.io.IOException;
import java.util.Date;

import javax.microedition.io.Connector;
import javax.microedition.pim.Event;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;


import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MessageArguments;
import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.system.EventLogger;

class Test {
    public static void main(String[] args){
        System.out.println("Starting Test");
        (new TestMenuItem(0)).registerInstance();
    }
}

class TestMenuItem extends ApplicationMenuItem
{
	MessageConnection mconn;
	TextMessage textmessage;
	public TestMenuItem(int order){super(order);}
	// TODO Auto-generated constructor stub}
	public void registerInstance()
	{
		ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CALENDAR,this);
        ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_CALENDAR,this);
	}
	
	public void unRegisterInstance(){

        ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CALENDAR,this);
    }
	public String toString() {
		// TODO Auto-generated method stub
		return "Test Item...";
	}
	
	class ConnectionThread extends Thread
	{
		boolean end;
		public ConnectionThread()
		{
			end = false;
		}
		public boolean getEnd()
		{
			return end;
		} 
		public void run()
		{
			try {
				mconn = (MessageConnection)Connector.open("sms://");
				Message message = (Message) mconn
			       .newMessage(MessageConnection.TEXT_MESSAGE);
				((javax.wireless.messaging.Message) message).setAddress("sms://10086");
				textmessage = (TextMessage)message;
			     textmessage.setPayloadText("dasdasdasd");
			     mconn.close();
			     end = true;
			     
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public Object run(Object context) {
		// TODO Auto-generated method stub	
		ConnectionThread thread = new ConnectionThread();
		thread.start();
		while(true)
		{
			if(thread.getEnd())
			{
				try
				{
					Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(textmessage) );
				}
				catch(Throwable t)
				{
					t.printStackTrace();
					return null;
				}
				break;
			}
		}

		return context;
	}
}

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: I get uncaught throwable. Any help would be appreciated

The RIM video What is the Event Log? should help.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Contributor
Posts: 7
Registered: ‎03-18-2010
My Device: 8300
My Carrier: student

Re: I get uncaught throwable. Any help would be appreciated

guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:GetActiveCall
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:Ret,0
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:GetHeld
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:Ret,0
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:GetIncoming
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:Ret,0
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:GetNetworkFeatures
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:39:46 2010  severity:5 type:2 app:CC data:Ret,212797
guid:0x631E5BCD6DC16354 time: Tue Mar 23 15:39:48 2010  severity:0 type:2 app:net.rim.sms data:INcn
guid:0xB2EC7A712090AD8F time: Tue Mar 23 15:39:49 2010  severity:0 type:2 app:net.rim.smsui data:UTSC
guid:0x631E5BCD6DC16354 time: Tue Mar 23 15:39:49 2010  severity:4 type:2 app:net.rim.sms data:TXst
guid:0x631E5BCD6DC16354 time: Tue Mar 23 15:39:49 2010  severity:5 type:2 app:net.rim.sms data:TXsb
guid:0x631E5BCD6DC16354 time: Tue Mar 23 15:39:49 2010  severity:5 type:2 app:net.rim.sms data:TSdi
guid:0x631E5BCD6DC16354 time: Tue Mar 23 15:39:49 2010  severity:4 type:2 app:net.rim.sms data:TXss
guid:0xB2EC7A712090AD8F time: Tue Mar 23 15:39:49 2010  severity:0 type:2 app:net.rim.smsui data:UTSC
guid:0x9C3CD62E3320B498 time: Tue Mar 23 15:39:50 2010  severity:1 type:3 app:Java Exception data:
	Throwable
	New count is invalid: -1
	net_rim_bb_framework_api-1
	 UnreadCount$NewAndUnreadCount
	 modifyUnreadCount
	 0x8BE3
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 <private>
	 0x8EA4
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 <private>
	 0x8E80
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 modifyUnreadCount
	 0x9014
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 decrementUnreadCount
	 0x8FDC
	net_rim_bb_sms
	 SMSModel
	 <private>
	 0x496F
	net_rim_bb_sms
	 SMSModel
	 perform
	 0x3718
	net_rim_bb_messaging
	 MessageBulkMarkOldManager
	 markOld
	 0x340A
	net_rim_bb_messaging
	 MessageBulkMarkOldManager$Worker
	 run
	 0x34A8
	net_rim_cldc-1
	 Thread
	 run
	 0xB6C5
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:50 2010  severity:0 type:2 app:System data:JVM Error 104
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:50 2010  severity:0 type:2 app:System data:Uncaught: Throwable
guid:0x9C3CD62E3320B498 time: Tue Mar 23 15:39:51 2010  severity:1 type:3 app:Java Exception data:
	Throwable
	New count is invalid: -1
	net_rim_bb_framework_api-1
	 UnreadCount$NewAndUnreadCount
	 modifyUnreadCount
	 0x8BE3
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 <private>
	 0x8EA4
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 <private>
	 0x8E8B
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 modifyUnreadCount
	 0x9014
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 decrementUnreadCount
	 0x8FDC
	net_rim_bb_sms
	 SMSModel
	 <private>
	 0x496F
	net_rim_bb_sms
	 SMSModel
	 perform
	 0x3718
	net_rim_bb_messaging
	 MessageBulkMarkOldManager
	 markOld
	 0x340A
	net_rim_bb_messaging
	 MessageBulkMarkOldManager$Worker
	 run
	 0x34A8
	net_rim_cldc-1
	 Thread
	 run
	 0xB6C5
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:51 2010  severity:0 type:2 app:System data:JVM Error 104
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:51 2010  severity:0 type:2 app:System data:Uncaught: Throwable
guid:0x9C3CD62E3320B498 time: Tue Mar 23 15:39:51 2010  severity:1 type:3 app:Java Exception data:
	Throwable
	New count is invalid: -1
	net_rim_bb_framework_api-1
	 UnreadCount$NewAndUnreadCount
	 modifyUnreadCount
	 0x8BE3
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 <private>
	 0x8EA4
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 modifyUnreadCount
	 0x9014
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 decrementUnreadCount
	 0x8FDC
	net_rim_bb_sms
	 SMSModel
	 <private>
	 0x496F
	net_rim_bb_sms
	 SMSModel
	 perform
	 0x3718
	net_rim_bb_messaging
	 MessageBulkMarkOldManager
	 markOld
	 0x340A
	net_rim_bb_messaging
	 MessageBulkMarkOldManager$Worker
	 run
	 0x34A8
	net_rim_cldc-1
	 Thread
	 run
	 0xB6C5
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:51 2010  severity:0 type:2 app:System data:JVM Error 104
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:51 2010  severity:0 type:2 app:System data:Uncaught: Throwable
guid:0x9C3CD62E3320B498 time: Tue Mar 23 15:39:52 2010  severity:1 type:3 app:Java Exception data:
	Throwable
	New count is invalid: -1
	net_rim_bb_framework_api-1
	 UnreadCount$NewAndUnreadCount
	 modifyUnreadCount
	 0x8BE3
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 <private>
	 0x8EA4
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 modifyUnreadCount
	 0x9014
	net_rim_bb_framework_api-1
	 UnreadCountManager
	 decrementUnreadCount
	 0x8FDC
	net_rim_bb_sms
	 SMSModel
	 <private>
	 0x4979
	net_rim_bb_sms
	 SMSModel
	 perform
	 0x3718
	net_rim_bb_messaging
	 MessageBulkMarkOldManager
	 markOld
	 0x340A
	net_rim_bb_messaging
	 MessageBulkMarkOldManager$Worker
	 run
	 0x34A8
	net_rim_cldc-1
	 Thread
	 run
	 0xB6C5
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:52 2010  severity:0 type:2 app:System data:JVM Error 104
guid:0x97C9F5F641D25E5F time: Tue Mar 23 15:39:52 2010  severity:0 type:2 app:System data:Uncaught: Throwable
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:40:01 2010  severity:5 type:2 app:CC data:IsActive
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:40:01 2010  severity:5 type:2 app:CC data:Ret,"false"
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:40:01 2010  severity:5 type:2 app:CC data:IsActive
guid:0xE68C69BA0F2EBA59 time: Tue Mar 23 15:40:01 2010  severity:5 type:2 app:CC data:Ret,"false"

 

Highlighted
New Contributor
Posts: 7
Registered: ‎03-18-2010
My Device: 8300
My Carrier: student

Re: I get uncaught throwable. Any help would be appreciated

I don't know where is the error.