Webville312 14 Newbie Poster

Hello all, I am trying to have my Midlet access a website address, but whenever I run it in the emulator, I get a "Null Pointer exception"
Here is the code I am using:

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.InputConnection;
import javax.microedition.lcdui.Display;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Webville
 */
class tRequest implements Runnable {

    String user, pass;
    HttpConnection conn;
    InputStream input;
    DataOutputStream output;
    new_ticket parent;
    String result;
    String url = "https://41.220.12.206/services/yopaymentsdev/portal/";
    StringBuffer sb = new StringBuffer();
    String an = null;

    tRequest(String user, String pass, new_ticket child) {
        this.user = user;
        this.pass = pass;
        this.parent = child;
    }

    public void start() {
        Thread th = new Thread(this);
        th.start();
    }
    // input = conn.openInputStream();

    public void run() {
        try {
            conn = (HttpConnection) Connector.open("https://41.220.12.206/services/yopaymentsdev/portal/",Connector.READ_WRITE);
            if (conn.getResponseCode() != HttpConnection.HTTP_NOT_FOUND) {
                input = conn.openInputStream();
                final int MAX_LENGTH = 128;
                byte[] buf = new byte[MAX_LENGTH];
                int total = 0;
                while (total < MAX_LENGTH) {
                    int count = input.read(buf, total, MAX_LENGTH - total);
                    if (count < 0) {
                        break;
                    }
                    total += count;
                }
                input.close();
                String reply = new String(buf, 0, total);
                conn.close();
            }
            //sb.append((char) c);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
//sb.append((char) c);
    }
}

Thanx in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.