Я пытаюсь подключиться к серверу apache localhost из моего приложения Android. Я копирую коды из блога (AndroidHive), поскольку я никогда не работал ни на одном из них раньше. Когда я пытаюсь подключиться к БД, я получаю следующие ошибки:
12-04 11:00:14.457 7039-7101/com.example.monkey.mysql_dump E/Buffer Error: Error converting result java.lang.NullPointerException: lock == null
12-04 11:00:14.457 7039-7101/com.example.monkey.mysql_dump E/JSON Parser: Error parsing data org.json.JSONException: End of input at character 0 of
12-04 11:00:14.457 7039-7101/com.example.monkey.mysql_dump W/dalvikvm: threadid=11: thread exiting with uncaught exception (group=0x41621c08)
12-04 11:00:14.467 7039-7101/com.example.monkey.mysql_dump E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Мой код приведен ниже:
public class All_products extends AppCompatActivity{
static InputStream is = null;
static String json = "";
static JSONObject jObj = null;
static List<NameValuePair> parameter = new ArrayList<NameValuePair>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_products);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
parameter.add(new BasicNameValuePair("cName", "Ibtehaz SHawon"));
parameter.add(new BasicNameValuePair("cID", "1004200"));
parameter.add(new BasicNameValuePair("cDue", "400"));
parameter.add(new BasicNameValuePair("cAmount", "1400"));
new doInb().execute();
}
class doInb extends AsyncTask<String, String, String>
{
@Override
protected String doInBackground(String... params) {
String insertLink = "http://localhost/BRACathon_ServerSide/db_insert.php";
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(insertLink);
httpPost.setEntity(new UrlEncodedFormEntity(parameter));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
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 + "
");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
Toast.makeText(getApplicationContext(), jObj.toString(), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj.toString();
}
}
Моя конфигурация сервера Apache
cName == varChar
cID == int
cDue == int
cAmount == int
Спасибо.
android,mysql,apache,