BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-20-2009, 10:26 AM   #1 (permalink)
ARB
New Member
 
Join Date: Feb 2009
Model: 8300
PIN: N/A
Carrier: telus
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Threading issue

Please Login to Remove!

I am having problems running a thread and am hoping that someone can please help me. The problem is that getreceiptxmldatathread.isXMLdata is null and when I trace through it appears as though the run method is called after setting the xmldata input stream. Can someone see an obvious problem that would help? Thanks.

GetReceiptXMLDataThread getreceiptxmldatathread = null;
InputStream xmldata = null;

//if GET IO thread exists...kill it first
if(null != getreceiptxmldatathread)
getreceiptxmldatathread.closeIO();
//create thread to get receipt data using HTTP
getreceiptxmldatathread = new GetReceiptXMLDataThread();
//run thread
getreceiptxmldatathread.start();
//set the input stream so we can close the thread
xmldata = getreceiptxmldatathread.isXMLdata;
//process the xml receipt data
processXMLData(xmldata, receiptobject);
//kill the thread
getreceiptxmldatathread.join();


class GetReceiptXMLDataThread extends Thread
{
private StreamConnection conn;
public InputStream isXMLdata;
private boolean killIOget; // flag to stop IOget thread

GetReceiptXMLDataThread()
{
conn = null;
isXMLdata = null;
killIOget = false;
}

public void run()
{
try
{
if (conn != null)
conn.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}

try
{
//format filename from PIN
String fileName = "";
fileName = Integer.toHexString(DeviceInfo.getDeviceId()) + ".txt";

//get the receipt data from server
conn=(StreamConnection)Connector.open
("204.15......./" + fileName);

//set the input stream with the XML
isXMLdata = conn.openInputStream();
}

catch (Exception e)
{
System.out.println(e.toString());
}

try
{
if (conn != null)
conn.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
Offline  
Old 08-20-2009, 08:32 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Gah. Do you write and debug you code without indentation?

Isn't this better? Have a read of this thread while we look at the code.

Quote:
Originally Posted by ARB View Post
Code:
GetReceiptXMLDataThread getreceiptxmldatathread = null;
InputStream xmldata = null;

//if GET IO thread exists...kill it first
if(null != getreceiptxmldatathread)
       getreceiptxmldatathread.closeIO();
//create thread to get receipt data using HTTP
getreceiptxmldatathread = new GetReceiptXMLDataThread();                         
//run thread                                
getreceiptxmldatathread.start(); 
//set the input stream so we can close the thread
xmldata = getreceiptxmldatathread.isXMLdata;
//process the xml receipt data
processXMLData(xmldata, receiptobject); 
//kill the thread
getreceiptxmldatathread.join();


class GetReceiptXMLDataThread extends Thread 
{
         private StreamConnection conn;
         public InputStream isXMLdata;
         private boolean killIOget; // flag to stop IOget thread
         
         GetReceiptXMLDataThread()
         {
             conn = null;
             isXMLdata = null;
             killIOget = false;
         }
         
         public void run() 
         {                
                try 
                {
                    if (conn != null)
                        conn.close();
                }
                catch(IOException e)
                {
                    System.out.println(e.getMessage());
                }
    
                try
                {
                    //format filename from PIN
                    String fileName = "";
                    fileName = Integer.toHexString(DeviceInfo.getDeviceId()) + ".txt";
 
                     //get the receipt data from server
                    conn=(StreamConnection)Connector.open
                    ("204.15......./" + fileName);
                    
                    //set the input stream with the XML
                    isXMLdata = conn.openInputStream();
                }

                catch (Exception e)
                {
                    System.out.println(e.toString());
                }
                
                try 
                {
                    if (conn != null)
                        conn.close();
                }
                catch(IOException e)
                {
                    System.out.println(e.getMessage());
                }
        }
Ok, so looking at it like this, there are obviously some things missing from GetReceiptXMLDataThread. Are you opening the connection on a file, socket, http, or what?
__________________
My other Blackberry is a PlayBook.

Last edited by hrbuckley : 08-20-2009 at 08:39 PM.
Offline  




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