我创建了一个活动,在选择单选按钮的情况下,将信息发送到数据库。一切正常,没有错误,但是当我编译并单击按钮时,应用程序崩溃了。找不到问题。这是我的代码
public class Mlo extends Activity {
private RadioButton vincinq, cinq;
private EditText num;
private RadioGroup tupe;
HttpPost httppost;
StringBuffer buffer;
HttpClient httpclient ;
private void createDialog(String title, String text)
{
// Création d'une popup affichant un message
AlertDialog ad = new AlertDialog.Builder(this)
.setPositiveButton("Ok", null).setTitle(title).setMessage(text)
.create();
ad.show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mlo);
vincinq = (RadioButton) findViewById(R.id.conv1);
cinq = (RadioButton) findViewById(R.id.conv2);
Button button1 = (Button) findViewById(R.id.button1);
tupe = (RadioGroup) findViewById(R.id.radioGroup1);
// Définition du listener du bouton
button1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
final String nb = num.getText().toString();
if (vincinq.isChecked()) {
final String type ="25";
final String nbnum = num.getText().toString();
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://forma-fun.comli.com/cheq.php");
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("numcompte", nbnum));
postParameters.add(new BasicNameValuePair("type", type));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpclient.execute(httppost);
Log.i("postData", response.getStatusLine().toString());
createDialog("Merci ", "Votre demande a été effectuée");
Intent i = new Intent(Mlo.this,VotreCompte.class);
startActivity(i);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
else
if (cinq.isChecked()){
final String type1 ="50";
final String nbnum = num.getText().toString();
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://forma-fun.comli.com/cheq.php");
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("numcompte", nbnum));
postParameters.add(new BasicNameValuePair("type", type1));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpclient.execute(httppost);
Log.i("postData", response.getStatusLine().toString());
createDialog("Merci ", "Votre demande a été effectuée");
Intent i = new Intent(Mlo.this,VotreCompte.class);
startActivity(i);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
}
});
}
}
日志猫
03-13 12:13:05.282: E/AndroidRuntime(363): FATAL EXCEPTION: main
03-13 12:13:05.282: E/AndroidRuntime(363): java.lang.NullPointerException
03-13 12:13:05.282: E/AndroidRuntime(363): at
com.example.attijaribank2.Mlo$1.onClick(Mlo.java:56)
03-13 12:13:05.282: E/AndroidRuntime(363): at
android.view.View.performClick(View.java:2485)
03-13 12:13:05.282: E/AndroidRuntime(363): at
android.view.View$PerformClick.run(View.java:9080)
03-13 12:13:05.282: E/AndroidRuntime(363): at
android.os.Handler.handleCallback(Handler.java:587)
03-13 12:13:05.282: E/AndroidRuntime(363): at
android.os.Handler.dispatchMessage(Handler.java:92)
03-13 12:13:05.282: E/AndroidRuntime(363): at android.os.Looper.loop(Looper.java:130)
03-13 12:13:05.282: E/AndroidRuntime(363): at
android.app.ActivityThread.main(ActivityThread.java:3683)
03-13 12:13:05.282: E/AndroidRuntime(363): at
java.lang.reflect.Method.invokeNative(Native Method)
03-13 12:13:05.282: E/AndroidRuntime(363): at
java.lang.reflect.Method.invoke(Method.java:507)
03-13 12:13:05.282: E/AndroidRuntime(363): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-13 12:13:05.282: E/AndroidRuntime(363): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-13 12:13:05.282: E/AndroidRuntime(363): at dalvik.system.NativeStart.main(Native
Method)