Problem mit HTTP- Verbindung

AnonymXX

Mitglied
Hallo,

in meinem Programm habe ich Probleme mit der HTTP- GET- Verbindung. Mein Programm besteht aus mehreren Forms. Am Anfang habe ich alle in einem MIDlet erzeugt, das war aber schnell unübersichtlich.

Daher habe ich jetzt für jedes Form eine eigene Klasse. Jetzt geht aber auf einmal die HTTP- Verbindung nicht mehr und ich weiß nicht, wo mein Fehler liegt :(

Das Form, in dem die Verbindung aufgebaut, und wo auch die URL zusammengesetzt wird:

Java:
public class ChoiceForm extends Form implements ItemCommandListener{

    private MIDlet midlet;
    private GetThread getThread;

    private ChoiceGroup cg2;
    public String wahl=null;
    private String URI;
    private final String [] umkreise = {"1km", "5km", "10km"};
    private final Command CMD_END = new Command("Ende", Command.EXIT, 1);
    private final Command CMD_BACK = new Command("Zurück", Command.BACK, 1);
    private final Command CMD_SEND = new Command("Senden", Command.ITEM, 1);

    public ChoiceForm(MIDlet midlet){
        super("App");
        this.midlet = midlet;
        cg2 = new ChoiceGroup("Sehenswürdigkeiten anzeigen: ", Choice.EXCLUSIVE, umkreise, null);
        cg2.setItemCommandListener(this);
        append(cg2);
        cg2.addCommand(CMD_END);
        cg2.addCommand(CMD_BACK);
        cg2.addCommand(CMD_SEND);


    }

    public void commandAction(final Command c, final Item i) {
        if(c == CMD_END) {
            midlet.notifyDestroyed();
        }
        if (c==CMD_BACK){
        	Display.getDisplay(midlet).setCurrent(new OptionForm(midlet));
        }
        if (c==CMD_SEND){

                //den GetThred initialisieren und starten
        	getThread = new GetThread(midlet);
			getThread.start();
			int index2 = cg2.getSelectedIndex();
                        wahl = cg2.getString(index2);
                        URI= "http://Servername/Beispiel.php?umkreis="+wahl+"&lonWert=49.4468&latWert=8.5708";
  
        }


  }
    public String getURI() {
		// TODO Auto-generated method stub
		return URI;
	}

}

Der Thread, in dem die Verbindug aufgebaut werden soll:

Java:
public class GetThread extends Thread {
	

	public GetThread(MIDlet midlet) {
		this.midlet = midlet;
	}

	public void interrupt(){
		anhalten = true;
	}
        

        
	public void run(){

                StringSeparator separator = new StringSeparator();
		StringBuffer sbuf = new StringBuffer();
		try{
                        //Verbindung aufbauen
                        choice = new ChoiceForm(midlet);

                        hc = (HttpConnection) Connector.open(choice.getURI());
			httpCode = hc.getResponseCode();
			is = hc.openInputStream();
			byte[] haeppchen = new byte[4096];
			int dieAnzahl;
                        //String vom Server einlesen
			while (!anhalten && (dieAnzahl = is.read(haeppchen))>0){
				sbuf.append(new String(haeppchen, 0, dieAnzahl));
			}

                        //Speicher für Array reservieren
                        ergebnis=new String[30][10];


                        /* Der String soll erst nach $ und dann nach , gesplittet werden
                         * sbuf: die Serverantwort. Wird dem String eingabe1 zugewiesen
                         * die Methode "split" wird zweimal aufgerufen und die aufgeteilten 
                         * Strings in das Array "ergebnis" geschrieben. 
                         */

                        String eingabe1=sbuf.toString();
                        
                        Vector vec1=separator.split(eingabe1,"§");
                        for(int i=0;i<vec1.size();i++)
                            {
                            //ergebnis[i][0]=(String)vec1.elementAt(i);
                            Vector vec2=separator.split((String)vec1.elementAt(i),",");
                            for(int j=0;j<vec2.size();j++)
                                {
                                ergebnis[i][j]=(String)vec2.elementAt(j);
                                }
                            }


                        /* das Array wird dem Hauptprogramm übergeben! Diese Übertragung geht ohne
                         * Probleme. Das Hauptprogramm bekommt die richtigen Werte und kann diese Anzeigen!
                         */
                        result.ergebnisAnzeigen(ergebnis);
                                             
                        
                        
		}
		catch(Exception e){
			
		}
		finally{
			try{
				if (is != null){
					is.close();
				}
			}
			catch (IOException e){}
			try {
				if(hc != null){
					hc.close();
				}
			}
			catch (IOException e){}
		}



	}
       

        private HttpConnection hc = null;
	private InputStream is = null;
	private int httpCode = 0;
	private MIDlet midlet;
        private ChoiceForm choice;
        private ResultForm result;
	private boolean anhalten = false;
        public String[][] ergebnis;
        public String ausgabe;

Soweit der Quellcode. Ich weiß nicht recht, wo das Problem liegt. Das Einzige, was ich durch Debugging herausfinden konnte, ist, dass der GetThread als URI null bekommt und nicht den richtigen String.
Woran kann das liegen?

Für Hilfe bin ich sehr dankbar.

Gruß

AnonymXX
 

The_S

Top Contributor
Du erstellst dir ne neue "Choice" in deinem "GetThread". Da steht natürlich in der URL null drin ... generell komische Struktur. Evtl. mal weng was über OOP lesen.
 

AnonymXX

Mitglied
Sorry,

hatte mich vertan. Es geht doch nicht so, wie ich es brauche.

Wie soll ich dann die URL vom ChoiceForm zum GetThread bekommen, wenn nicht so?
Für Vorschläge wäre ich sehr dankbar.

Gruß

AnonymXX
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Prüfen, ob App auf Gerät installiert ist Problem S10 Android & Cross-Platform Mobile Apps 11
W In App Purchase Problem? Android & Cross-Platform Mobile Apps 36
W Problem mit Android Studio Android & Cross-Platform Mobile Apps 0
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
K Android to Pi | Websocket Problem Android & Cross-Platform Mobile Apps 3
N Intent und finish() Problem Android & Cross-Platform Mobile Apps 5
B Android App Programmierung Einsteiger Problem Android & Cross-Platform Mobile Apps 4
emeraldo Android Problem mit Bottomnavmenu Android & Cross-Platform Mobile Apps 10
I Das Problem mit der Tastatur... android:windowSoftInputMode="adjustPan" Android & Cross-Platform Mobile Apps 1
M Android App → Problem mit dem Speichern von einem Bitmap–Objekt. Android & Cross-Platform Mobile Apps 1
A Android Android Studio Emulator Problem Android & Cross-Platform Mobile Apps 1
S Android Studio Bluetooth App Problem Android & Cross-Platform Mobile Apps 6
J TicTacToe Problem bei kontrolle Android & Cross-Platform Mobile Apps 7
J Button array ID Problem Android & Cross-Platform Mobile Apps 2
M Problem bei Werteübergabe, MSQL verbindung Android & Cross-Platform Mobile Apps 3
S Android Problem mit Android Virtual Device erstellung. Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
S Android Android java onclick listener Problem Android & Cross-Platform Mobile Apps 9
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
K Problem mit arraylist und button Android & Cross-Platform Mobile Apps 16
R W-Lan Problem über Sockets Android & Cross-Platform Mobile Apps 1
P ViewPager Problem Android & Cross-Platform Mobile Apps 1
A Android Problem mit Video von Youtube abspielen Android & Cross-Platform Mobile Apps 4
A Android Problem mit Zurücktaste und ausgabe der Aktuellen Seite Android & Cross-Platform Mobile Apps 6
B Android Problem mit Soundwiedergabe Android & Cross-Platform Mobile Apps 2
T Android Android Sensor: Java Problem Android & Cross-Platform Mobile Apps 1
G Problem beim Rendern von 3D-Objekt Android & Cross-Platform Mobile Apps 0
L Android Gyroscope Sensor Problem Android & Cross-Platform Mobile Apps 2
S Android GPS Problem Android & Cross-Platform Mobile Apps 24
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 1
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 0
B Android Problem mit Rückgabewert Android & Cross-Platform Mobile Apps 13
L Android komisches Bitmap-Größe-Problem Android & Cross-Platform Mobile Apps 8
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
R Problem mit View in ScrollView Android & Cross-Platform Mobile Apps 6
R Eclipse + AndroidSDK - Problem mit Referenzen Android & Cross-Platform Mobile Apps 6
M Problem mit setOnClickListener Android & Cross-Platform Mobile Apps 4
DaniSahne96 Problem beim Appdebuggen auf Smartphone Android & Cross-Platform Mobile Apps 3
P Android Problem beim Widget - Denkfehler ? Android & Cross-Platform Mobile Apps 2
M GCM IntentService Problem Android & Cross-Platform Mobile Apps 3
D Android Gallery Problem Android & Cross-Platform Mobile Apps 5
P Problem mit Cell id Android & Cross-Platform Mobile Apps 6
L Android Problem mit "spinner" Android & Cross-Platform Mobile Apps 10
D Android problem mit geschwindigkeitsberechnung app Android & Cross-Platform Mobile Apps 2
E Android Problem mit Contact Provider Android & Cross-Platform Mobile Apps 1
H Android Problem mit ListActivity Android & Cross-Platform Mobile Apps 3
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
F Android ExpandableList, SimpleCursorTreeAdapter, Cursor Problem Android & Cross-Platform Mobile Apps 2
A Android Problem mit Long.getLong() bzw. Integer.getInteger() Android & Cross-Platform Mobile Apps 2
V [Java] und [JavaME] ClientServer StreamConnection . Problem beim lesen / schreiben Android & Cross-Platform Mobile Apps 2
F Eclipse JAD File erzeugen -- Problem Android & Cross-Platform Mobile Apps 10
R Ein Problem beim ausführen von folgendem Quelltext Android & Cross-Platform Mobile Apps 11
M Problem mit dem Auslesen von System Properties Android & Cross-Platform Mobile Apps 7
P wtk problem Android & Cross-Platform Mobile Apps 3
G Math exp() Problem Android & Cross-Platform Mobile Apps 4
G S40 Problem Android & Cross-Platform Mobile Apps 8
A Problem beim Subtrahieren eines Double von einem Double Android & Cross-Platform Mobile Apps 5
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
S Image Problem Android & Cross-Platform Mobile Apps 11
M Problem mit den Softkeys Android & Cross-Platform Mobile Apps 4
G J2ME jar-problem Android & Cross-Platform Mobile Apps 10
S Komisches Problem Android & Cross-Platform Mobile Apps 3
F Problem beim Erstellen der Jar File Android & Cross-Platform Mobile Apps 4
A Problem: Canvas-Grösse Motorola RAZR v3r Android & Cross-Platform Mobile Apps 8
S Problem mit Einbindung einer externer Bibliothek Android & Cross-Platform Mobile Apps 2
G Random - Problem Android & Cross-Platform Mobile Apps 5
E problem mit den resourcen Android & Cross-Platform Mobile Apps 2
O Problem mit Datagramconnection Android & Cross-Platform Mobile Apps 2
P Problem mit der Uhrzeit Android & Cross-Platform Mobile Apps 2
S Problem auf dem Handy Android & Cross-Platform Mobile Apps 3
Besset Android http request an interne ip adresse funktioniert nicht Android & Cross-Platform Mobile Apps 8
T Fehler Android Studio: java.net.MalformedURLException: no protocol: http%3A%2F%2Fwww.mal ..... Android & Cross-Platform Mobile Apps 2
L Android Daten von Webseite runterladen, die mit HTTP-Authentifizierung gesichert ist Android & Cross-Platform Mobile Apps 5
S Android kriege einfach keine HTTP Connection hin Android & Cross-Platform Mobile Apps 1
B Android HTTP Login mit Cookies? Android & Cross-Platform Mobile Apps 3
N Android Http-Post mit Parametern... wie? Android & Cross-Platform Mobile Apps 3
N Error in HTTP operation beim KXML parsen Android & Cross-Platform Mobile Apps 7
M HTTP Post benutzen Android & Cross-Platform Mobile Apps 2
L HTTP via Bluetooth Android & Cross-Platform Mobile Apps 2
K HTTP-Verbindung mit J2ME.... Android & Cross-Platform Mobile Apps 2
missy72 Kotlin SSH Verbindung mit JSch Android & Cross-Platform Mobile Apps 5
J Android VPN Verbindung herstellen? Android & Cross-Platform Mobile Apps 4
B Android TCP-Verbindung zum Server über welche Prozess auslagerung nutzen? Android & Cross-Platform Mobile Apps 1
H WIFI, Bluetooth und NFC Verbindung überwachen Android & Cross-Platform Mobile Apps 1
H Android 3G TCP Socket Verbindung zum PC durch NAT Android & Cross-Platform Mobile Apps 8
T Android MSSQL Verbindung herstellen - Android Studio Android & Cross-Platform Mobile Apps 2
M Android Server-Client-Verbindung in Android-App mit Sockets aufbauen Android & Cross-Platform Mobile Apps 5
W Android HTTPS-Verbindung mit Client-Authentifizierung Android & Cross-Platform Mobile Apps 0
R Socket Verbindung AsycTask Android & Cross-Platform Mobile Apps 5
F Android USB Verbindung zu Windows Programm Android & Cross-Platform Mobile Apps 3
U Android Https-Verbindung Android & Cross-Platform Mobile Apps 2
K Java ME Bluetooth verbindung parameter Android & Cross-Platform Mobile Apps 3
N Java ME Server-Client Verbindung über Wifi Android & Cross-Platform Mobile Apps 6
N Handy -PC Verbindung Android & Cross-Platform Mobile Apps 2
N Blutooz-Verbindung ... ich schaffs nicht Android & Cross-Platform Mobile Apps 5
F Server - Client Verbindung mit Java ME Android & Cross-Platform Mobile Apps 3
G Bluetooth Verbindung zwischen Handy und PC Android & Cross-Platform Mobile Apps 5
G Bluetooth Verbindung Android & Cross-Platform Mobile Apps 2
O Bluetooth Verbindung zwischen 2 Handys Android & Cross-Platform Mobile Apps 5

Ähnliche Java Themen

Neue Themen


Oben