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: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

isn't "providing full code" what a developer is paid for?
----------------------------------------------------------
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
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

Did you get my query atleast by now.

 

 

My target is to build a Live TV app  using xml parser concept uisng Java.

 

 

My url i.e xml.aspx contains channel images,names and url's  which are to be parsed.

 

 

 

 

 

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

I would suggest that you post a code snippet of the part that you have issues with, together with a description of what you want to do, what your code does instead and what measures you already tried.

i doubt that you will find somebody who writes the application for you for free.
----------------------------------------------------------
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
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

Ok I will send you  the basic example with  which Iam starting  my Application        

Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class MyClass extends UiApplication {
    public static void main(String[] args)
    {
        MyClass theApp = new MyClass();
        theApp.enterEventDispatcher();
    }

    public MyClass()
    {
        pushScreen(new HomeNavigationScreen());
    }
}

class HomeNavigationScreen extends MainScreen
{
    private ListField navField;
    private Vector navItems;
    Connection _connectionthread;

    public HomeNavigationScreen()
    {

        setTitle("my app");

        navItems = new Vector();
        navField = new ListField();

        ListCallback callBack = new ListCallback();
        navField.setCallback(callBack);

        _connectionthread = new Connection();
        _connectionthread.start();


        add(navField);

    }
    
    
    public String getXml(String url){
		String xml = new String();
		try {
			StreamConnection s = null;
            s = (StreamConnection)Connector.open(url);
            HttpConnection httpConn = (HttpConnection)s; 
			
			int status = httpConn.getResponseCode();
			if (status == HttpConnection.HTTP_OK){
                InputStream input = s.openInputStream();

                byte[] data = new byte[256];
                int len = 0;
                int size = 0;
                StringBuffer raw = new StringBuffer();
                    
                while ( -1 != (len = input.read(data)) ){
                	raw.append(new String(data, 0, len));
                    size += len;    
                }
                xml = raw.toString();
                  
                input.close();
			}
		} catch (IOException e) {
			//Control de la exception de la conexion al servidor
			e.printStackTrace();
		}
		return xml;
	}
 

    private class ListCallback implements ListFieldCallback
    {
        public void drawListRow(ListField list, Graphics g, int index, int y, int w)
        {
            String text = (String) this.get(list, index);

            g.drawText(text, 0, y, 0, w);
        }

        public Object get(ListField listField, int index) {
            return navItems.elementAt(index);
        }

        public int getPreferredWidth(ListField listField) {
            return Display.getWidth();
        }

        public int indexOfList(ListField listField, String prefix, int start) {
            return navItems.indexOf(prefix, start);
        }
    }

    private class Connection extends Thread{
        public Connection(){
            super();
        }

        public void run(){
            // define variables later used for parsing
            Document doc;
            StreamConnection conn;
            try{
                conn = (StreamConnection)Connector.open(" My url ending with xml.aspx");
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                docBuilder.isValidating();
                doc = docBuilder.parse(conn.openInputStream());
                doc.getDocumentElement().normalize();
                NodeList list = doc.getElementsByTagName("Event");

                for (int i=0;i<list.getLength();i++){

                    Node currNode = list.item(i);

                    if (currNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element currElement = (Element) currNode;

                        NodeList titleList = currElement.getElementsByTagName("title");
                        Element titleElem = (Element) titleList.item(0);
                        NodeList titleNode = titleElem.getChildNodes();
                        String title = ((Node) titleNode.item(0)).getNodeValue();

                        navItems.addElement(title);
                        navField.insert(i);
                    }   
                }
            }
            catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}

 I have opened a New Java Poject and named  it as ParseXML

 

 

 

and then created or added a new class called  MyClass.java

 

 

Now please guide me from here

 

 

Shall i give my url    which is to be parsed   in MyClass.java    at

 

 

try{
conn = (StreamConnection)Connector.open("     ");

 

 

 

When I run on the siumlator  nothing is happening except it is showing a blank screen .

 

 

 

 

 

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

please check this:
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

your connection thread looks ok, but you should add more debug output to see what is going on. check the response code of a connection to see if it succeeds, for example.
if you want to modify an UI element, like the listfield, from a separate thread you have to use invokelater.
----------------------------------------------------------
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
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

add more debug output    ?

 

 

 

pls give me the code 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

System.out.println("my little debug output");
this is helpful in all kind of places, especially when catching an exception.
printStackTrace does nothing on an exception, if you want a stacktrace you will have to catch a Throwable.
----------------------------------------------------------
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
Developer
ankur_siwach
Posts: 148
Registered: ‎09-28-2012
My Device: Blackberry Developer

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

did to open the link which i have sent you..

its content the source code..which help you about xml parsing..then its up to you which type of data you want to parse..


----------------------------------------------------------
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.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520

Re: Iam new to java programming .I have started Java apps development and able to build the sample XML Demo given in the Eclipse SDK Version: 3.7.2 for BlackBerry OS

I did'nt find any code in it except the video about blocking and unblocking the vents and something.

 

 

Please be brief once again