Bonjour,
Je développe actuellement une application android avec des sockets et quand je la lance elle s'arrête.Cette application permet d'envoyer des commandes d'une Nexus 7 sous Android KitKat vers un boitier domotique (IPX 800) via le protocole M2M. L'application fonctionne très bien sous Android 2.2 mais pas sur 4.4.2.
Voici le logCat qd je lance l'application :
voici le code java de mon application :
Je développe actuellement une application android avec des sockets et quand je la lance elle s'arrête.Cette application permet d'envoyer des commandes d'une Nexus 7 sous Android KitKat vers un boitier domotique (IPX 800) via le protocole M2M. L'application fonctionne très bien sous Android 2.2 mais pas sur 4.4.2.
Voici le logCat qd je lance l'application :
Citation:
01-30 07:25:06.183: W/dalvikvm(995): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 01-30 07:25:06.273: E/AndroidRuntime(995): FATAL EXCEPTION: main 01-30 07:25:06.273: E/AndroidRuntime(995): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.domotique/com.android.domotique.Admin}: java.lang.NullPointerException 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.access0(ActivityThread.java:141) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.os.Handler.dispatchMessage(Handler.java:99) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.os.Looper.loop(Looper.java:137) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.main(ActivityThread.java:5041) 01-30 07:25:06.273: E/AndroidRuntime(995): at java.lang.reflect.Method.invokeNative(Native Method) 01-30 07:25:06.273: E/AndroidRuntime(995): at java.lang.reflect.Method.invoke(Method.java:511) 01-30 07:25:06.273: E/AndroidRuntime(995): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 01-30 07:25:06.273: E/AndroidRuntime(995): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 01-30 07:25:06.273: E/AndroidRuntime(995): at dalvik.system.NativeStart.main(Native Method) 01-30 07:25:06.273: E/AndroidRuntime(995): Caused by: java.lang.NullPointerException 01-30 07:25:06.273: E/AndroidRuntime(995): at com.android.domotique.Admin.onCreate(Admin.java:117) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.Activity.performCreate(Activity.java:5104) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 01-30 07:25:06.273: E/AndroidRuntime(995): ... 11 more |
voici le code java de mon application :
Code:
package com.android.domotique;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;
public class Admin extends MainActivity {
private Button bPrecedent;
private Button bSuivant;
private ToggleButton Relai1;//Eclairage 1
private ToggleButton Relai2;//Eclairage Ext
private ToggleButton Relai3;//Eclairage Degagement
private ToggleButton Relai4;//Portail
String AdresseIP = "10.129.101.193";
int Port = 9870;
Socket SocketIPX;
PrintWriter BuffW ;
BufferedReader BuffR;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bPrecedent = new Button(this);
Relai1 = new ToggleButton(this);
Relai2 = new ToggleButton(this);
Relai3 = new ToggleButton(this);
Relai4 = new ToggleButton(this);
setContentView(R.layout.admin);
bPrecedent = (Button)findViewById(R.id.Buttonpre);
Relai1 = (ToggleButton)findViewById(R.id.toggleButton1);
Relai2 = (ToggleButton)findViewById(R.id.toggleButton2);
Relai3 = (ToggleButton)findViewById(R.id.toggleButton3);
Relai4 = (ToggleButton)findViewById(R.id.toggleButton4);
bPrecedent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
Relai1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Thread tTest = new Thread(){
public void run(){
if(Relai1.isChecked())
CommunicationIPX("Set11");
else
CommunicationIPX("Set10");
}
};
tTest.start();
}
});
Relai2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(Relai2.isChecked())
CommunicationIPX("Set21");
else
CommunicationIPX("Set20");
}
});
Relai3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(Relai3.isChecked())
CommunicationIPX("Set31");
else
CommunicationIPX("Set30");
}
});
Relai4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(Relai1.isChecked())
CommunicationIPX("Set41");
else
CommunicationIPX("Set40");
}
});
bSuivant.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
try {
InetAddress serverAddr = Inet4Address.getByName(AdresseIP);
SocketIPX = new Socket(serverAddr, Port);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
//ouverture du buffeur pour envoyer dans le socket qu'on vient de créer
try {
BuffW = new PrintWriter(new BufferedWriter(new OutputStreamWriter(SocketIPX.getOutputStream())),true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//idem pour recevoir
try {
BuffR = new BufferedReader(new InputStreamReader(SocketIPX.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String CommunicationIPX(String Ordre){
String sClientMsg = "";
//envoie l'ordre passé en argument de la fonction en l'état (si c'est un truc qui n'existe pas, l'IPX nous le dira)
BuffW.println(Ordre);
BuffW.flush();
//lire la réponse
try {
sClientMsg = BuffR.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return la réponse de l'IPX
return sClientMsg;
}//fin Communication IPX
}
Aucun commentaire:
Enregistrer un commentaire