connexion d'android a un serveur apache
je travaille sur un projet qui consiste a faire une application client serveur, mon client c un mobile android en ce moment je travaille avec un emulateur, j'ai un probleme au niveau de la connexion de l emulateur a un serveur Apache,
j'ai crée une base de donnée, et j'ai pris ce code dans une discussion ici...voici le code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| package com.example.fatima;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Main extends Activity implements OnClickListener {
Button button;
EditText edit;
private HttpURLConnection connection;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 =((Button)this.findViewById(R.id.button1));
EditText editText1 =((EditText)this.findViewById(R.id.editText1));
button.setOnClickListener(this);
if(this.getIntent().getExtras()!=null)
{
String s="Hello";
//s=this.getIntent().getExtras().getString("Data");
edit.setText(s);
}
}
public void onClick(View arg0) {
String nom = null;
String prenom = null;
try {
String myurl="http://127.0.0.1:8080//www/android.php?nom="+nom+"&prenom="+prenom+"";
URL url;
url = new URL(myurl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
Intent intent= new Intent(this,Main.class);
intent.putExtra("Data", nom);
this.startActivityForResult(intent, 1000);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
mais ca marche pas..il m affiche des erreurs dans le logcat:
Citation:
02-27 16:23:12.052: E/Trace(1647): error opening trace file: No such file or directory (2)
02-27 16:23:12.843: D/AndroidRuntime(1647): Shutting down VM
02-27 16:23:12.843: W/dalvikvm(1647): threadid=1: thread exiting with uncaught exception (group=0xb5f0d288)
02-27 16:23:12.903: E/AndroidRuntime(1647): FATAL EXCEPTION: main
02-27 16:23:12.903: E/AndroidRuntime(1647): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fatima/com.example.fatima.Main}: java.lang.NullPointerException
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.os.Looper.loop(Looper.java:137)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-27 16:23:12.903: E/AndroidRuntime(1647): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 16:23:12.903: E/AndroidRuntime(1647): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 16:23:12.903: E/AndroidRuntime(1647): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-27 16:23:12.903: E/AndroidRuntime(1647): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-27 16:23:12.903: E/AndroidRuntime(1647): at dalvik.system.NativeStart.main(Native Method)
02-27 16:23:12.903: E/AndroidRuntime(1647): Caused by: java.lang.NullPointerException
02-27 16:23:12.903: E/AndroidRuntime(1647): at com.example.fatima.Main.onCreate(Main.java:29)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.Activity.performCreate(Activity.java:5008)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-27 16:23:12.903: E/AndroidRuntime(1647): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-27 16:23:12.903: E/AndroidRuntime(1647): ... 11 more
02-27 16:23:20.823: I/Process(1647): Sending signal. PID: 1647 SIG: 9
aidez moi .. je suis debutante dans android et java et :merci: