Im getting a null point exception when i runs this code.
what i tried to do is… get the useremail from the application to the string uemail and tried to fetch the friends who are friends with uemail.
activity
public class MainActivity extends Activity {
protected static final String TAG_Name = null;
int a;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a = 2;
Button ref = (Button)findViewById(R.id.button1);
ref.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
InputStream is = null;
String result = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
String uemail = String.valueOf(a);
nameValuePairs.add(new BasicNameValuePair("place_id", uemail));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.hopscriber.com/test.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection" + e.toString());
}
// convert response to stringtry
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
JSONArray jsonArray = new JSONArray(result);
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = (JSONObject) jsonArray.get(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_Name, object.getString("place_id"));
contactList.add(map);
}
}
TextView z = (TextView)findViewById(R.id.textView1);
z.setText(TAG_Name);
} catch (Exception e) {
e.printStackTrace();
}
}
});
php
<?php
include "db_config.php";
$q=mysql_query("SELECT 'name' FROM places WHERE place_id='".$_REQUEST['place_id']."'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
i seems can’t find the answer…. please help me out.. it tigers null
I noticed an issue with the
mysql_queryline and where the following" WHERE uname='".$_REQUEST['uemail']."'");not being escaped properly onWHEREclause.The correct PHP is below.
Your java looks fine as long as you’re never invoking
tryme()(say in a main method without defininguserNameprior).