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
Contributor
Posts: 11
Registered: ‎07-29-2011
My Device: BlackBerry Bold 9800
My Carrier: Telkomsel
Accepted Solution

how to use Getter Setter in class extends thread ?

[ Edited ]
package mypackage;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.microedition.io.HttpConnection;
import javax.microedition.xml.rpc.Element;

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

import net.rim.device.api.io.messaging.UsernamePasswordCredentials;
import net.rim.device.api.io.transport.ConnectionFactory;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

public class search extends Thread{
private MainScreen scren;

String nul = "";
MyScreen a = new MyScreen();



	
	public void run() {// define variables later used for parsing
    	System.out.println("MASUK SEARCH!!!");
    	String url = "http://localhost/ms/password.xml";
        Document doc = null;
        HttpConnection conn = null;
        try{
        	
        	
        	
            //providing the location of the XML file,
            //your address might be different
            conn=(HttpConnection) new ConnectionFactory().getConnection(url).getConnection();
            System.out.println(conn.toString());
            conn.setRequestProperty("User-Agent",
            "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
            conn.setRequestMethod(HttpConnection.GET);
            //next few lines creates variables to open a
            //stream, parse it, collect XML data and
            //extract the data which is required.
            //In this case they are elements,
            //node and the values of an element
            if(conn.getResponseCode()== HttpConnection.HTTP_OK){
            DocumentBuilderFactory docBuilderFactory= DocumentBuilderFactory. newInstance();
            System.out.println("masuk Sini");
            
            InputStream inputStream = conn.openInputStream();
            
            byte[] data = new byte[256];
            int len = 0;
            int size =0;
            StringBuffer raw = new StringBuffer();   
            while(-1 !=(len =inputStream.read(data))){
            	raw.append(new String(data,0,len));
            	size +=len;
            }
            String content = raw.toString();
            InputStream input = new ByteArrayInputStream(content.getBytes());
            
            
            DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();
            docBuilder.isValidating();
            System.out.println("dan sini");
            docBuilderFactory.setIgnoringElementContentWhitespace(true);
            
               
                                   
             
//            Element root= doc.getDocumentElement();
//            System.out.println(root.toString());
//            
//            Element operation = (Element) root.getOwnerDocument();
//            System.out.println(operation.toString());
//            String layer = operation.getAttribute("Category");
//            System.out.println(layer);
//            root.normalize();
            System.out.println("terakhir");
            
//            System.out.println("Category:"+layer);
            doc = docBuilder.parse(input);
            doc.getDocumentElement().normalize();
            NodeList list=doc.getElementsByTagName("password");
       System.out.println("Atleast!");
            
           String _node=new String();
           String  _element = new String();
            //this "for" loop is used to parse through the
            //XML document and extract all elements and their
            //value, so they can be displayed on the device

            for (int i=0;i<list.getLength();i++){
                Node value=list.item(i).getChildNodes().item(0);
                _node=list.item(i).getNodeName();
                
                _element=value.getNodeValue();
                
                if(_node.equals("password")){
                	System.out.println("NODE=: "+_element);
                	
                	nul = _element;
                	
                	setPass(_element);
                	Dialog.inform(getPass());
//                	Dialog.inform(userpass.getPassword()+"Di search");
                	
                		break;
                }
                else{
                	System.out.println("Null is detected!!!!!");
                }
                
            }
            }
            
            //end for

        }//end try

        //will catch any exception thrown by the XML parser
        catch (Exception e){
            System.out.println(e.toString()+"ini salahnya...");
        }
		
		// TODO Auto-generated method stub
		
        
	}
	userPass userpass(userPass dapet){
		dapet.setPassword(getPass());
		return dapet;
		
	}
	
	public void setPass(String a){
		a = nul;
	}
	public String getPass(){
		return nul;
	}
	 public void updateField(final String node){
	        //receiving the parsed node and its value from the thread
	        //and updating it here
	        //so it can be displayed on the screen

	        final String title="user";
	        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
				
				public void run() {
					
					if(node.equals(title)){
						
//						_screen.add(new RichTextField("User" + node));
					}
					
				}
			});

	    }

}

 sorry for my bad english

that's my code,

 

i want to pass the _Node String , which is i get it from parse XML ,to another class.

 

can i get the string? thanks

 

Contributor
Posts: 11
Registered: ‎07-29-2011
My Device: BlackBerry Bold 9800
My Carrier: Telkomsel

Re: how to use Getter Setter in class extends thread ?

already done -_-

user OOP :smileyhappy: