On the click event add data to MySQL database through php on the localhost. Its showing following logcat error on the click event. Please help me to sove this problem.
08-11 06:19:27.858: D/gralloc_goldfish(917): Emulator without GPU emulation detected.
08-11 06:20:44.804: D/Inside Click(917): aaaaaaa
08-11 06:20:44.861: W/System.err(917): java.lang.NullPointerException
08-11 06:20:44.887: W/System.err(917): at com.example.connectiondemo.MainActivity$1.onClick(MainActivity.java:81)
08-11 06:20:44.898: W/System.err(917): at android.view.View.performClick(View.java:3480)
08-11 06:20:44.907: W/System.err(917): at android.view.View$PerformClick.run(View.java:13983)
08-11 06:20:44.927: W/System.err(917): at android.os.Handler.handleCallback(Handler.java:605)
08-11 06:20:44.927: W/System.err(917): at android.os.Handler.dispatchMessage(Handler.java:92)
08-11 06:20:44.937: W/System.err(917): at android.os.Looper.loop(Looper.java:137)
08-11 06:20:44.937: W/System.err(917): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-11 06:20:44.937: W/System.err(917): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 06:20:45.007: W/System.err(917): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-11 06:20:45.007: W/System.err(917): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-11 06:20:45.027: W/System.err(917): at dalvik.system.NativeStart.main(Native Method)
My programme
package com.example.connectiondemo;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String url="http://10.0.2.2/styletapphp/create_booking.php";
private static final String TAG_SUCCESS="Success";
JSONParser jsonParser;
JSONObject json;
TextView t1,t2,t3,t4,t5,t6,t7,t8,t9;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(TextView) findViewById(R.id.t1);
t2=(TextView) findViewById(R.id.t2);
t3=(TextView) findViewById(R.id.t3);
t4=(TextView) findViewById(R.id.t4);
t5=(TextView) findViewById(R.id.t5);
t6=(TextView) findViewById(R.id.t6);
t7=(TextView) findViewById(R.id.t7);
t8=(TextView) findViewById(R.id.t8);
t9=(TextView) findViewById(R.id.t8);
t1.setText("Date");
t2.setText("Stylist");
t3.setText("9to10");
t4.setText("10to11");
t5.setText("11to12");
t6.setText("12to1");
t7.setText("2to3");
t8.setText("3to4");
Button butt1= (Button) findViewById(R.id.b1);
butt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Inside Click","aaaaaaa");
List<NameValuePair>namevaluepair=new ArrayList<NameValuePair>();
namevaluepair.add(new BasicNameValuePair("bookingdate",t1.getText().toString()));
namevaluepair.add(new BasicNameValuePair("stylist",t2.getText().toString()));
namevaluepair.add(new BasicNameValuePair("status9to10",t3.getText().toString()));
namevaluepair.add(new BasicNameValuePair("status10to11",t4.getText().toString()));
namevaluepair.add(new BasicNameValuePair("status11to12",t5.getText().toString()));
namevaluepair.add(new BasicNameValuePair("status12to1",t6.getText().toString()));
namevaluepair.add(new BasicNameValuePair("status2to3",t7.getText().toString()));
namevaluepair.add(new BasicNameValuePair("status3to4",t8.getText().toString()));
try{
json=jsonParser.makehttpRequest(url,"POST",namevaluepair);
int success=json.getInt(TAG_SUCCESS);
t9.setText("Added Successfully"+success);
}catch(JSONException e){
e.printStackTrace();
}catch(NullPointerException e){
e.printStackTrace();
}
//new CreateBooking().execute();
}
});
}
}
0 comments:
Post a Comment