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
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

"Ok please  give me the next steps"

 

Answer my questions, I think there are outstanding questions (perhaps the same question) from all these posts. 

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

Just to make sure you understand where I am coming from, I am not going to provide you with the solution to your problem.  Instead I am going to try to guide you to finding the solution for yourself.  This is an education for you, the idea being that then you will understand your own code and be able to debug/test and fix it yourself. 

Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

[ Edited ]

In continuation top the last query

 

 

I have made soem minor changes in the application.

 

 

 

1)Please see that the click event  happens with only one click

 

 

without extra option "show" etc   or options etc

 

 

 

2)Show the languages list like     

 

 

Events

 

 

English

 

 

Hindi

 

Tamil

 

 

etc in Vertical manner

 

 

3)

 

When clicked on the langauge  

 

 

That   langaauge  channels list   (with images and names) should be displayed

 

 

why   error  "invalid link" coming always.

 

 

My modified code which is working very well in  java and midlet supported  nokia  mobile  

 

package mypackage;

import java.io.*;
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.microedition.media.*;
import javax.microedition.media.control.VideoControl;

class Channel {    
	public String cName;    
	public String cId;    
	public String cType;
	public String cLanguage;
	public String cImage;
	public String cLink;
	public String cBandwidth;
	public String cCellnapid;
}

class ChannelListHandler extends DefaultHandler {    

	Channel currentChannel;
	private String lastCharacters;   
	
	private Vector channelList;     
	
	public ChannelListHandler() {        
		channelList = new Vector();    
	}     
	
	public Channel[] getChannels() {       
		Channel[] channels = new Channel[channelList.size()];        
		channelList.copyInto(channels);        
		return channels;    
	}
	
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {    
		if (qName.equals("channel")) {        
			currentChannel = new Channel();    
			}
		}
	
	public void characters(char[] ch, int start, int length) throws SAXException {    
		lastCharacters = new String(ch, start, length).trim();
		} 
	
	public void endElement(String uri, String localName, String qName) throws SAXException {    
		if (qName.equals("name")) {        
			currentChannel.cName=lastCharacters;    		
		} else if (qName.equals("id")) {        
			currentChannel.cId=lastCharacters;    		
		} else if (qName.equals("type")) {        
			currentChannel.cType=lastCharacters;    		
		} else if (qName.equals("language")) {        
			currentChannel.cLanguage=lastCharacters;    		
		} else if (qName.equals("image")) {        
			currentChannel.cImage=lastCharacters;    		
		} else if (qName.equals("link")) {        
			currentChannel.cLink=lastCharacters;    		
		} else if (qName.equals("bandwidth")) {        
			currentChannel.cBandwidth=lastCharacters;    		
		} else if (qName.equals("cellnapid")) {        
			currentChannel.cCellnapid=lastCharacters;    
			channelList.addElement(currentChannel);
			currentChannel=null;
		}
	}	
}

public class MainMidlet extends MIDlet implements CommandListener, ItemCommandListener, PlayerListener, Runnable {     
	private Form form; 
	private Channel[] channels;
	
	private Vector[] languageChannels; 
	/*
	private Vector channelHindi; 
	private Vector channelEnglish; 
	private Vector channelTelugu; 
	private Vector channelTamil; 
	private Vector channelMalayalam; 
	private Vector channelKannada;
	*/ 
	
	int formState = -1;
	
	private Display d;
	private Player p;
	private Canvas c;
	private Command exitCommand = new Command("Exit", Command.EXIT, 1);
	VideoControl vc;
	
	public MainMidlet() {
		d = Display.getDisplay(this);
		languageChannels = new Vector[7];
		for ( int i=0; i<7; i++ ) languageChannels[i] = new Vector();
	}
	
	public void playLink(String link) {
	 	c = new Canvas() {
	 			protected void paint(Graphics g) {
	 				g.setColor(0, 0, 0);
	 				g.fillRect(0, 0, getWidth(), getHeight());
	 			}};

	 	c.setFullScreenMode(true);
	 	c.addCommand(exitCommand);
	 	c.setCommandListener(this);
	 	d.setCurrent(c);

	 	try {
	 		p = Manager.createPlayer(link);
	 		p.addPlayerListener(this);
	 		p.start();
	 		vc = (VideoControl) p.getControl("javax.microedition.media.control.VideoControl");
	 		vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, c);
	 	} catch (Exception e) { 
	 		showAlert("playLink: " + e.toString()); 
	 	}
	 }
	
	public void playerUpdate(Player player, java.lang.String event, java.lang.Object eventData) {
	 	if (player.getState() == Player.STARTED) {

	 		try {
	 			vc.setDisplayFullScreen(true);
	 			vc.setVisible(true);
	 		} catch (Exception e) {
	 			showAlert("playerUpdate: " + e.toString());
	 		}
	 	}
	 	if (player.getState() == Player.CLOSED)
	 	{
	 		d.setCurrent(form);
	 	}
	}

	public void showAlert(String aAlertText) {
		Alert alert = new Alert("Alert", aAlertText, null, AlertType.ERROR);
		alert.setTimeout(10000);
		d.setCurrent(alert, form);
	 }
	
	public void startApp() {        
		if (form == null) {            
			form = new Form("YuppTV");            
			form.addCommand(new Command("Exit", Command.EXIT, 0));            
			form.setCommandListener(this);             
			// start parsing            
			(new Thread(this)).start();        
			}        
		Display.getDisplay(this).setCurrent(form);    
		}     
	
	public void pauseApp() {}     
		
	public void destroyApp(boolean must) {}     
	
	public void commandAction(Command c, Displayable d) {        
		if (c.getCommandType() == Command.EXIT) {            
			notifyDestroyed();        
			}
		} 
	
	public void commandAction(javax.microedition.lcdui.Command arg0, javax.microedition.lcdui.Item item) {
		int size = form.size();
		int index = -1;
		for ( int i=0; i<size; i++ ) {
			if ( item == form.get(i) ) { index = i; break; }
		}
		if ( index > -1 ) {
			if ( formState == -1 ) { ChannelsAvailable(index); formState = index; }
			else {
				Channel ch = (Channel)languageChannels[formState].elementAt(index);
				playLink(ch.cLink);
			}
		}
	}
	
	public Image loadImage(String url) throws IOException {
	    HttpConnection hpc = null;
	    DataInputStream dis = null;
	    Image image = null;   
	    try {
	      hpc = (HttpConnection) Connector.open(url);
	      int length = (int) hpc.getLength();
	      byte[] data = new byte[length];
	      dis = new DataInputStream(hpc.openInputStream());
	      dis.readFully(data);	      
	      try {
	    	  image = Image.createImage(data, 0, data.length);
	      } catch (IllegalArgumentException e) {}
	    } catch (Exception e) {            
	    } finally {
	      if (hpc != null) hpc.close();
	      if (dis != null) dis.close();   
	    }
	    return image;
	}
	    
	public void run() {        
		try {            	
			ChannelListHandler handler = new ChannelListHandler();                       
			SAXParser parser = SAXParserFactory.newInstance().newSAXParser();             
			
			channels = null;
			StreamConnection con = null;
			InputStream ins = null;
			
			try {
				con = (StreamConnection)Connector.open("http://yupptv.com/mobile/symbianxmlnew.aspx;deviceside=true");
				ins = con.openInputStream();           
				parser.parse(ins, handler);
			 } catch (Exception e) {            
				 form.append(e.toString());        
			 }	finally {             		
				 channels = handler.getChannels(); 
				 if (con != null) con.close();
				 if (ins != null) ins.close();
			 }
			
			if (channels != null && channels.length > 0) {
				form.deleteAll();
				FillData();
				NewLanguage("Events",form);
				NewLanguage("Hindi",form);
				NewLanguage("English",form);
				NewLanguage("Telugu",form);
				NewLanguage("Tamil",form);
				NewLanguage("Malayalam",form);
				NewLanguage("Kannada",form);
			} else {               
				form.append("(no channels)\n");           
			}
		} catch (Exception e) {            
			form.append(e.toString());        
		}	
	}
	
	private void NewLanguage(String lang, Form frm) {
		StringItem item = new StringItem("",lang, Item.BUTTON);
	    Command cmd = new Command("Show", Command.ITEM, 1);
		item.addCommand(cmd);
		item.setDefaultCommand(cmd);
		item.setItemCommandListener(this);
		frm.append(item);
	}
	
	private void ChannelsAvailable(int index) {
		form.deleteAll();
		try {			
			for ( int i=0; i<languageChannels[index].size(); i++ ) {
				Channel ch = (Channel)languageChannels[index].elementAt(i);
				Image image = loadImage(ch.cImage);
				if ( image == null ) form.append("\nInvalid image link!\n");
				else {
					ImageItem item = new ImageItem(ch.cName, image, Item.BUTTON | Item.LAYOUT_LEFT, "");
					Command cmd = new Command("PLAY", Command.ITEM, 1);
					item.addCommand(cmd);
					item.setDefaultCommand(cmd);
					item.setItemCommandListener(this);
					form.append(item);
				}
			}
		} catch (Exception e) { form.append(e.toString());  }	
	}
	
	private void FillData() {
		try {  
			for (int i = 0; i < channels.length; i++) {
				if ( channels[i].cLanguage.equals("Events") ) languageChannels[0].addElement(channels[i]); 
				else if ( channels[i].cLanguage.equals("Hindi") ) languageChannels[1].addElement(channels[i]); 
				else if ( channels[i].cLanguage.equals("English") ) languageChannels[2].addElement(channels[i]); 
				else if ( channels[i].cLanguage.equals("Telugu") ) languageChannels[3].addElement(channels[i]); 
				else if ( channels[i].cLanguage.equals("Tamil") ) languageChannels[4].addElement(channels[i]); 
				else if ( channels[i].cLanguage.equals("Malayalam") ) languageChannels[5].addElement(channels[i]); 
				else if ( channels[i].cLanguage.equals("Kannada") ) languageChannels[6].addElement(channels[i]); 				
			}
		} catch (Exception e) { form.append(e.toString());  }	
	}
}

 

 

Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

k I have already answered you That Iam unable  to debug using the eclipse  either on the emulator or on the device.

 

 

But I have answered  by giving results of  3 t tests  which you asked me to do.

 

Now please go thru my new query peter .

 

 

Thanks

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

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

The information that you have given us to indicate a problem is this:

 

"why   error  "invalid link" coming always."

 

But you don't tell us where this  comes from, or how your code gets to this point.  Sorry I am not a good enough guesser to figure this out for myself.  And I am not sure that I should have to - you get the error, you have the debugger, so it seems pretty easy for you to tell us.  Can you do that?

 

You said:

"But I have answered  by giving results of  3 t tests  which you asked me to do"

 

Have you done everything I asked you to do?  For example, have you done what I asked in this post:

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-help-me-parse-my-the-contents-con...

 

You ran a series of tests, these tests should have given you some information about what changes you needed to make.  By comparing the tests that worked and the tests that did not, you could have reached some conclusions regarding this.  I asked you to do this and report back.  But so far you don't seem to have told us what conclusion you have come too.  The tests were not for me, they were for you to investigate. 

 

Let me repeat my comment from my last post

 

I am not going to provide you with the solution to your problem.  Instead I am going to try to guide you to finding the solution for yourself.  This is an education for you, the idea being that then you will understand your own code and be able to debug/test and fix it yourself. 

Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

No I have used  

 

try {
con = (StreamConnection)Connector.open("http://yupptv.com/mobile/symbianxmlnew.aspx;deviceside=true");
ins = con.openInputStream();
parser.parse(ins, handler);
} catch (Exception e) {
form.append(e.toString());
} finally {
channels = handler.getChannels();
if (con != null) con.close();
if (ins != null) ins.close();
}

 

 

 

intead of just     as below: But why invalid image  link! as outout

 

please explain

 

(StreamConnection)Connector.open
(“socket:// testserver:600;interface=wifi”);
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

Have you answered my questions?

 

1) Have you described the conclusions that you have drawn from the tests that you did, noting the changes  you made and reviewing the KB article I referred you to?

 

2) Have you identified the line in your code that is giving you the error and how you get to that line?

 

Sorry, I am going to stop trying to help you since you do not seem interested in helping me or yourself.

Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

No I will once again perform all the tests on my deviice and BB

9860 and Simulator BB 9330 actually I was in hurry for the quick and complete solution.
Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

Result of First test

 

Kept a break point on the two lines:

con = (HttpConnection)Connector.open..

and

ins = con.openInputStream();

and run my  test.  

a) Got to line starting "con..." 

 

Answer         No

 

 

 

b) Got to line starting "ins"

 

Answer         No

 

Exception

 

 

java.io.InterruptedIOException: Local connection timed out after - 120000   (no channels)

 

 

 

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

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

Just running the tests again is not answering my question.  Please review question (1) from my previous post again.

 

The duration of this thread and the length of time before you respond does not support your statement that you are in a hurry.  But if you really are in a hurry, then I suggest you find someone who understands BlackBerry networking and pay them to fix your code. 

Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Can anyone help me parse my the contents contained in the" url" named as xml.aspx using pure Java Application

I have no Idea    but I can say that due to the break points    the parsing is not happenning and showing the output as

 

 

java i/o exception  -12000 (no channels).

 

 

 

Please use plain text.