Erro no httpconnection, alguem ajuda?

I ae galera,
To com problemas a executar esse codigo aqui :

 if (command == cmdBuscar) {                     
                // Insert pre-action code here
               new Thread(new Runnable() {
		            public void run(){
		            	url = "http://localhost/teste.php?Vid_cliente="+txtCliente.getString();
		        		try{
							getConsulta(url);
						}catch (IOException e) {
							alerta.setString(e.getMessage());
							alerta.setType(AlertType.WARNING);
							alerta.setTimeout(Alert.FOREVER);
			}                                                    
            }
		        }).start();             

O erro que apresenta é o seguinte:
Uncaught exception java/lang/NullPointerException.

O erro que está dando é porque você não fez o catch para NullPointerException.
Verifique o método getConsulta e veja se não existe alguma variável que não foi iniciada antes de ser usada.

Uma pergunta simples, porque voce está usando thread???
Outra voce já estudou ou leu algum artigo sobre thread ou programação paralela???

Pow, esse codigo eu peguei como exemplo, ele funciona bem pq esta em uma classe so. mas eu estou mudando ela pra outras coisas.

Galera, estou postando pra voces o metodo getConsulta. sou novo na parada e nao to conseguindo isso ae, se alguem puder ajudar.
Esse codigo foi me enviado por um rapaz aqui do topic.

public void getConsulta(String url) throws IOException {
	   	StringBuffer b  = new StringBuffer();
	   	String aux="";
	   	try{
			HttpConnection con = (HttpConnection)Connector.open(url);
			InputStream inputStream = con.openInputStream();
			int ch;
			int status = -1;
			status 	= con.getResponseCode();

			if(status == HttpConnection.HTTP_OK){
				con.close();
				while((ch = inputStream.read()) != -1) {
					b.append((char) ch);
				}
				for(int i = 0;i<b.toString().length();i++){
			    	if(b.toString().substring(i,i+1).equals("#")){
			    		aux		= aux+"\n";
			    	}
			    	else{
			    		aux		= aux+b.toString().substring(i,i+1);
			    	}
			    }
				this.alerta.setString(aux);
				this.alerta.setType(AlertType.INFO);
				this.alerta.setTimeout(Alert.FOREVER);
			}
			else{
				this.alerta.setString("Erro: Conexão");
				this.alerta.setType(AlertType.WARNING);
				this.alerta.setTimeout(Alert.FOREVER);
			}
		}
		catch(IOException ioe){
			this.alerta.setString(ioe.getMessage());
			this.alerta.setType(AlertType.ERROR);
			this.alerta.setTimeout(Alert.FOREVER);
                     }catch (Exception e) {
                           alerta.setString(e.getMessage());
                           alerta.setType(AlertType.ERROR);
                           alerta.setTimeout(Alert.FOREVER);
                                                }
		//displayPrincipal.setCurrent(this.alerta);
	}

Por favor, poste o stacktrace completo

HeHe, vamos por parte
que é isso??
rsrsrs,

sou novo na parada.

Bom, to postando o codigo inteiro do meu projeto de teste.
Estou fazendo ele no NetBeans

package Office;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
//Aqui o nescessario para funcionar o acesso remoto
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;


/**
 *
 * @author Admin
 */
public class Office extends MIDlet implements CommandListener {
    
    /** Creates a new instance of Office */
    public Office() {
        initialize();
    }
    
    private org.netbeans.microedition.lcdui.SplashScreen telaSplash;                     
    private Form frmPrincipal;
    private Command cmdSair;
    private Command cmdAjuda;
    private Form frmLogin;
    private TextField txtUsuario;
    private Command cmdOk;
    private Command cmdSair1;
    private Alert alLoginerror;
    private Form formCadastro;
    private Alert alertCadastro;
    private Form formLogin;
    private TextField txt_usuario;
    private Command cmd_Ok;
    private Command cmd_Sair;
    private Command cmd_Chamado;
    private Form formChamado;
    private Command cmdBuscar;
    private Command cmdSair_ch;
    private Alert alerta;
    private TextField txtCliente;                   
    //parte de trazer dados remotos
    private String url;
                     

    /** Called by the system to indicate that a command has been invoked on a particular displayable.                      
     * @param command the Command that ws invoked
     * @param displayable the Displayable on which the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {                    
    // Insert global pre-action code here
        if (displayable == frmPrincipal) {                     
            if (command == cmdAjuda) {                   
                // Insert pre-action code here
                // Do nothing                       
                // Insert post-action code here
            } else if (command == cmdSair) {                     
                // Insert pre-action code here
                exitMIDlet();                       
                // Insert post-action code here
            } else if (command == cmd_Chamado) {                     
                // Insert pre-action code here
                getDisplay().setCurrent(get_formChamado());                        
                // Insert post-action code here
            }                       
        } else if (displayable == telaSplash) {
            if (command == telaSplash.DISMISS_COMMAND) {                     
                // Insert pre-action code here
                getDisplay().setCurrent(get_formLogin());                       
                // Insert post-action code here
            }                      
        } else if (displayable == frmLogin) {
            if (command == cmdSair1) {                    
                // Insert pre-action code here
                // Do nothing                        
                // Insert post-action code here
            } else if (command == cmdOk) {                      
                // Insert pre-action code here
            if(txtUsuario.getString().equals("Fellipe")){
                //getDisplay().setCurrent(get_alertCadastro(), get_formCadastro());
            } else {
                getDisplay().setCurrent(get_alertCadastro(), get_formCadastro());               
                
            }   
                
            // Do nothing                        
                // Insert post-action code here
            }                       
        } else if (displayable == formLogin) {
            if (command == cmd_Sair) {                     
                // Insert pre-action code here
                exitMIDlet();                        
                // Insert post-action code here
            } else if (command == cmd_Ok) {                      
                // Insert pre-action code here
           if(txt_usuario.getString().equals("fellipe") ){
             getDisplay().setCurrent(get_frmPrincipal());  
           } else {
              getDisplay().setCurrent(get_alLoginerror(), get_formLogin());                 
           }    
                
                
                
           // Do nothing                        
                // Insert post-action code here
            }                       
        } else if (displayable == formChamado) {
            if (command == cmdBuscar) {                     
                // Insert pre-action code here
               new Thread(new Runnable() {
		            public void run(){
		              url = "http://localhost/teste.php?Vid_cliente="+txtCliente.getString();
                              	try{
							getConsulta(url);
						}catch (IOException e) {
							alerta.setString(e.getMessage());
                                                  	alerta.setType(AlertType.WARNING);
							alerta.setTimeout(Alert.FOREVER);
						}catch (Exception e) {
                                                    alerta.setString("Teste");
                                                    alerta.setType(AlertType.ERROR);
                                                    alerta.setTimeout(Alert.FOREVER);
                                                }
		            }
		        }).start();                 
                        // Do nothing                        
                // Insert post-action code here
            } else if (command == cmdSair_ch) {                      
                // Insert pre-action code here
                getDisplay().setCurrent(get_frmPrincipal());                        
                // Insert post-action code here
            }                       
        }                     
    // Insert global post-action code here
}                   

    /** This method initializes UI of the application.                        
     */
    private void initialize() {                      
        // Insert pre-init code here
        getDisplay().setCurrent(get_telaSplash());                      
        // Insert post-init code here
    }                     
    
    /**
     * This method should return an instance of the display.
     */
    public Display getDisplay() {                         
        return Display.getDisplay(this);
    }                        
    
    /**
     * This method should exit the midlet.
     */
    public void exitMIDlet() {                         
        getDisplay().setCurrent(null);
        destroyApp(true);
        notifyDestroyed();
    }                        

    /** This method returns instance for telaSplash component and should be called instead of accessing telaSplash field directly.                        
     * @return Instance for telaSplash component
     */
    public org.netbeans.microedition.lcdui.SplashScreen get_telaSplash() {
        if (telaSplash == null) {                      
            // Insert pre-init code here
            telaSplash = new org.netbeans.microedition.lcdui.SplashScreen(getDisplay());                       
            telaSplash.setCommandListener(this);
            telaSplash.setFullScreenMode(true);
            telaSplash.setText("Carregando o sistema ...");
            telaSplash.setTimeout(3000);                     
            // Insert post-init code here
        }                      
        return telaSplash;
    }                    
    /** This method returns instance for frmPrincipal component and should be called instead of accessing frmPrincipal field directly.                        
     * @return Instance for frmPrincipal component
     */
    public Form get_frmPrincipal() {
        if (frmPrincipal == null) {                      
            // Insert pre-init code here
            frmPrincipal = new Form("Sistema de Atendimentos", new Item[0]);                       
            frmPrincipal.addCommand(get_cmdSair());
            frmPrincipal.addCommand(get_cmdAjuda());
            frmPrincipal.addCommand(get_cmd_Chamado());
            frmPrincipal.setCommandListener(this);                     
            // Insert post-init code here
        }                      
        return frmPrincipal;
    }                    

    /** This method returns instance for cmdSair component and should be called instead of accessing cmdSair field directly.                        
     * @return Instance for cmdSair component
     */
    public Command get_cmdSair() {
        if (cmdSair == null) {                      
            // Insert pre-init code here
            cmdSair = new Command("Sair", Command.EXIT, 1);                      
            // Insert post-init code here
        }                      
        return cmdSair;
    }                    

    /** This method returns instance for cmdAjuda component and should be called instead of accessing cmdAjuda field directly.                        
     * @return Instance for cmdAjuda component
     */
    public Command get_cmdAjuda() {
        if (cmdAjuda == null) {                      
            // Insert pre-init code here
            cmdAjuda = new Command("Help", Command.HELP, 1);                      
            // Insert post-init code here
        }                      
        return cmdAjuda;
    }                    

    /** This method returns instance for frmLogin component and should be called instead of accessing frmLogin field directly.                         
     * @return Instance for frmLogin component
     */
    public Form get_frmLogin() {
        if (frmLogin == null) {                       
            // Insert pre-init code here
            frmLogin = new Form(null, new Item[] {get_txtUsuario()});                        
            frmLogin.addCommand(get_cmdOk());
            frmLogin.addCommand(get_cmdSair1());
            frmLogin.setCommandListener(this);                      
            // Insert post-init code here
        }                       
        return frmLogin;
    }                     

    /** This method returns instance for txtUsuario component and should be called instead of accessing txtUsuario field directly.                         
     * @return Instance for txtUsuario component
     */
    public TextField get_txtUsuario() {
        if (txtUsuario == null) {                       
            // Insert pre-init code here
            txtUsuario = new TextField("Usuario :", null, 120, TextField.ANY);                       
            // Insert post-init code here
        }                       
        return txtUsuario;
    }                     

    /** This method returns instance for cmdOk component and should be called instead of accessing cmdOk field directly.                         
     * @return Instance for cmdOk component
     */
    public Command get_cmdOk() {
        if (cmdOk == null) {                       
            // Insert pre-init code here
            cmdOk = new Command("Ok", Command.OK, 1);                       
            // Insert post-init code here
        }                       
        return cmdOk;
    }                     

    /** This method returns instance for cmdSair1 component and should be called instead of accessing cmdSair1 field directly.                         
     * @return Instance for cmdSair1 component
     */
    public Command get_cmdSair1() {
        if (cmdSair1 == null) {                       
            // Insert pre-init code here
            cmdSair1 = new Command("Sair", Command.EXIT, 1);                       
            // Insert post-init code here
        }                       
        return cmdSair1;
    }                     

    /** This method returns instance for alLoginerror component and should be called instead of accessing alLoginerror field directly.                         
     * @return Instance for alLoginerror component
     */
    public Alert get_alLoginerror() {
        if (alLoginerror == null) {                       
            // Insert pre-init code here
            alLoginerror = new Alert(null, "Usuario invalido !", null, AlertType.ERROR);                        
            alLoginerror.setTimeout(-2);                      
            // Insert post-init code here
        }                       
        return alLoginerror;
    }                     

    /** This method returns instance for formCadastro component and should be called instead of accessing formCadastro field directly.                         
     * @return Instance for formCadastro component
     */
    public Form get_formCadastro() {
        if (formCadastro == null) {                       
            // Insert pre-init code here
            formCadastro = new Form(null, new Item[0]);                       
            // Insert post-init code here
        }                       
        return formCadastro;
    }                     

    /** This method returns instance for alertCadastro component and should be called instead of accessing alertCadastro field directly.                         
     * @return Instance for alertCadastro component
     */
    public Alert get_alertCadastro() {
        if (alertCadastro == null) {                       
            // Insert pre-init code here
            alertCadastro = new Alert(null, "<Enter Text>", null, null);                        
            alertCadastro.setTimeout(-2);                      
            // Insert post-init code here
        }                       
        return alertCadastro;
    }                     

    /** This method returns instance for formLogin component and should be called instead of accessing formLogin field directly.                         
     * @return Instance for formLogin component
     */
    public Form get_formLogin() {
        if (formLogin == null) {                       
            // Insert pre-init code here
            formLogin = new Form(null, new Item[] {get_txt_usuario()});                        
            formLogin.addCommand(get_cmd_Ok());
            formLogin.addCommand(get_cmd_Sair());
            formLogin.setCommandListener(this);                      
            // Insert post-init code here
        }                       
        return formLogin;
    }                     

    /** This method returns instance for txt_usuario component and should be called instead of accessing txt_usuario field directly.                         
     * @return Instance for txt_usuario component
     */
    public TextField get_txt_usuario() {
        if (txt_usuario == null) {                       
            // Insert pre-init code here
            txt_usuario = new TextField("Usuario", null, 120, TextField.ANY);                       
            // Insert post-init code here
        }                       
        return txt_usuario;
    }                     

    /** This method returns instance for cmd_Ok component and should be called instead of accessing cmd_Ok field directly.                         
     * @return Instance for cmd_Ok component
     */
    public Command get_cmd_Ok() {
        if (cmd_Ok == null) {                       
            // Insert pre-init code here
            cmd_Ok = new Command("Ok", Command.OK, 1);                       
            // Insert post-init code here
        }                       
        return cmd_Ok;
    }                     

    /** This method returns instance for cmd_Sair component and should be called instead of accessing cmd_Sair field directly.                         
     * @return Instance for cmd_Sair component
     */
    public Command get_cmd_Sair() {
        if (cmd_Sair == null) {                       
            // Insert pre-init code here
            cmd_Sair = new Command("Exit", Command.EXIT, 1);                       
            // Insert post-init code here
        }                       
        return cmd_Sair;
    }                     

    /** This method returns instance for cmd_Chamado component and should be called instead of accessing cmd_Chamado field directly.                         
     * @return Instance for cmd_Chamado component
     */
    public Command get_cmd_Chamado() {
        if (cmd_Chamado == null) {                       
            // Insert pre-init code here
            cmd_Chamado = new Command("Chamado", Command.OK, 1);                       
            // Insert post-init code here
        }                       
        return cmd_Chamado;
    }                     

    /** This method returns instance for formChamado component and should be called instead of accessing formChamado field directly.                         
     * @return Instance for formChamado component
     */
    public Form get_formChamado() {
        if (formChamado == null) {                       
            // Insert pre-init code here
            formChamado = new Form("Busca de Chamados", new Item[] {get_txtCliente()});                        
            formChamado.addCommand(get_cmdBuscar());
            formChamado.addCommand(get_cmdSair_ch());
            formChamado.setCommandListener(this);                      
            // Insert post-init code here
        }                       
        return formChamado;
    }                     

    /** This method returns instance for cmdBuscar component and should be called instead of accessing cmdBuscar field directly.                         
     * @return Instance for cmdBuscar component
     */
    public Command get_cmdBuscar() {
        if (cmdBuscar == null) {                       
            // Insert pre-init code here
            cmdBuscar = new Command("Buscar", Command.OK, 1);                       
            // Insert post-init code here
        }                       
        return cmdBuscar;
    }                     

    /** This method returns instance for cmdSair_ch component and should be called instead of accessing cmdSair_ch field directly.                         
     * @return Instance for cmdSair_ch component
     */
    public Command get_cmdSair_ch() {
        if (cmdSair_ch == null) {                       
            // Insert pre-init code here
            cmdSair_ch = new Command("Voltar", Command.EXIT, 1);                       
            // Insert post-init code here
        }                       
        return cmdSair_ch;
    }                     

    /** This method returns instance for alerta component and should be called instead of accessing alerta field directly.                         
     * @return Instance for alerta component
     */
    public Alert get_alerta() {
        if (alerta == null) {                       
            // Insert pre-init code here
            alerta = new Alert(null, null, null, null);                        
            alerta.setTimeout(-2);                      
            // Insert post-init code here
        }                       
        return alerta;
    }                     

    /** This method returns instance for txtCliente component and should be called instead of accessing txtCliente field directly.                         
     * @return Instance for txtCliente component
     */
    public TextField get_txtCliente() {
        if (txtCliente == null) {                       
            // Insert pre-init code here
            txtCliente = new TextField("Codigo do cliente", null, 120, TextField.ANY);                       
            // Insert post-init code here
        }                       
        return txtCliente;
    }                     
    
    public void startApp() {
        
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
	public void getConsulta(String url) throws IOException {
	   	StringBuffer b  = new StringBuffer();
	   	String aux="";
	   	try{
			HttpConnection con = (HttpConnection)Connector.open(url);
			InputStream inputStream = con.openInputStream();
			int ch;
			int status = -1;
			status 	= con.getResponseCode();

			if(status == HttpConnection.HTTP_OK){
				con.close();
				while((ch = inputStream.read()) != -1) {
					b.append((char) ch);
				}
				for(int i = 0;i<b.toString().length();i++){
			    	if(b.toString().substring(i,i+1).equals("#")){
			    		aux		= aux+"\n";
			    	}
			    	else{
			    		aux		= aux+b.toString().substring(i,i+1);
			    	}
			    }
				this.alerta.setString(aux);
				this.alerta.setType(AlertType.INFO);
				this.alerta.setTimeout(Alert.FOREVER);
			}
			else{
				this.alerta.setString("Erro: Conexão");
				this.alerta.setType(AlertType.WARNING);
				this.alerta.setTimeout(Alert.FOREVER);
			}
		}
		catch(IOException ioe){
			this.alerta.setString(ioe.getMessage());
			this.alerta.setType(AlertType.ERROR);
			this.alerta.setTimeout(Alert.FOREVER);
                     }catch (Exception e) {
                           alerta.setString(e.getMessage());
                           alerta.setType(AlertType.ERROR);
                           alerta.setTimeout(Alert.FOREVER);
                                                }
		//displayPrincipal.setCurrent(this.alerta);
	}


}

Stacktrace

Tem um servidor de PHP rodando na máquina que você está executando o seu programa?

[edit]Depois que eu vi que a o texto do link acima era muito teórico. Veja este aqui.

Sim, o servidor PHP esta nessa maquina e funcionando.

O mais estranho é que esse codigo eu peguei de um exemplo, e no exemplo funciona direitinho.

Desculpe o tom crítico, mas o comentário acima não vai ajudar a resolver o seu problema.

Tente debugar o seu código e veja onde está o erro. Gere o Stacktrace.
Desculpe, mas eu não tenho tempo para ficar olhando todo o código. Se você não consegue descobrir em que ponto do código está dando o erro, eu não vou poder mais ajudar.

Bom vamos a algumas perguntas:
:arrow:Esse codigo era originalmente para celulares??? Pois o que vejo é que voce esta programando utilizando o J2ME correto???
:arrow:Se for J2ME qual é o WTK que voce está usando?? Eu aconcelharia utilizar o ultimo que ja vem junto coom netbeans 6.0

E um detalhe, não sei se estou certo mas no codigo abaixo voce fecha a conexão e depois tenta ler o InputStream??? Pelo que eu saiba voce so pode ler o InputStream se a conexão estiver aberta nao é???

HttpConnection con = (HttpConnection)Connector.open(url);   
            InputStream inputStream = con.openInputStream();   
            int ch;   
            int status = -1;   
            status  = con.getResponseCode();   
  
            if(status == HttpConnection.HTTP_OK){   
                con.close();   -- Aqui --
                while((ch = inputStream.read()) != -1) {   
                    b.append((char) ch);   
                }   
                for(int i = 0;i<b.toString().length();i++){   
                    if(b.toString().substring(i,i+1).equals("#")){   
                        aux     = aux+"\n";   
                    } 
                   .
                   .
                   .

[quote=lucifeler]Uma pergunta simples, porque voce está usando thread???
[/quote]

pra usar HTTPConnection tem q ser assim,ou estou enganado?

Consegui,

Antes do codigo:

this.alerta.setString(aux);   
                this.alerta.setType(AlertType.INFO);   
                this.alerta.setTimeout(Alert.FOREVER);   

Inseri o get_Alerta(), nao estava funcionando por isso. depois so chamei ele no fim do metodo.

Obrigado a todos que ajudaram.