Click here to Skip to main content
15,891,864 members
Home / Discussions / Android
   

Android

 
QuestionCan html5 css and javascript apps run on andriod o.s Pin
Member 105466963-Mar-14 9:27
Member 105466963-Mar-14 9:27 
AnswerRe: Can html5 css and javascript apps run on andriod o.s Pin
Kornfeld Eliyahu Peter9-Mar-14 1:26
professionalKornfeld Eliyahu Peter9-Mar-14 1:26 
QuestionAndroid control smart home Pin
Member 106395783-Mar-14 4:42
Member 106395783-Mar-14 4:42 
AnswerRe: Android control smart home Pin
Member 106536898-Mar-14 5:57
Member 106536898-Mar-14 5:57 
GeneralRe: Android control smart home Pin
Richard MacCutchan9-Mar-14 2:28
mveRichard MacCutchan9-Mar-14 2:28 
AnswerRe: Android control smart home Pin
Kornfeld Eliyahu Peter9-Mar-14 1:38
professionalKornfeld Eliyahu Peter9-Mar-14 1:38 
QuestionRooting on all android device Pin
sanjeev badoni1-Mar-14 3:22
sanjeev badoni1-Mar-14 3:22 
QuestionAndroid Programming JSONParsing Error Pin
Cyber1226-Feb-14 2:00
Cyber1226-Feb-14 2:00 
I have simple android project that inserts and retrieves some data from MySQL DB using PHP Scripts and JSONParser.

The Project is done using AsyncTask, when I press Insert button, the Progress Dialog Starts then after sometime it displays the message "Unfortunately 'App_Name' has stopped." in Eclipse Emulator.

I have done the following and many others....

*AndroidManifest.xml is set with all required(Permissions)
*I'm using URL_Insert="http://10.0.2.2/foldername/insert.php";

Do I need to configure WAMP Server.....?
Please tell me all possible causes of on button click crash from your experience.

HERE IS MY LOG CAT ERROR

02-26 10:23:58.570: E/Buffer Error(1065): Error converting result java.lang.NullPointerException: lock == null
02-26 10:23:58.670: E/JSON Parser(1065): Error parsing data org.json.JSONException: End of input at character 0 of
02-26 10:23:59.000: E/AndroidRuntime(1065): FATAL EXCEPTION: AsyncTask #5
02-26 10:23:59.000: E/AndroidRuntime(1065): java.lang.RuntimeException: An error occured while executing doInBackground()

Here is May JSONParser.java

package com.example.estate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
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.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

// function get json from url
// by making HTTP POST or GET mehtod
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {

// Making HTTP request
try {

// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);

HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}


} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException 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 + "\n");
}
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);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}

public JSONObject getJSONFromUrl(final String url) {

// Making HTTP request
try {
// Construct the client and the HTTP request.
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);

// Execute the POST request and store the response locally.
HttpResponse httpResponse = httpClient.execute(httpPost);
// Extract data from the response.
HttpEntity httpEntity = httpResponse.getEntity();
// Open an inputStream with the data content.
is = httpEntity.getContent();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
// Create a BufferedReader to parse through the inputStream.
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
// Declare a string builder to help with the parsing.
StringBuilder sb = new StringBuilder();
// Declare a string to store the JSON object data in string form.
String line = null;

// Build the string until null.
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}

// Close the input stream.
is.close();
// Convert the string builder data to an actual string.
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// Try to parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// Return the JSON Object.
return jObj;

}
}

Thank You!

-- modified 27-Feb-14 4:34am.
Questiontakes too long to run android simulator, looking for alternatives. Pin
ankum1623-Feb-14 18:33
ankum1623-Feb-14 18:33 
AnswerRe: takes too long to run android simulator, looking for alternatives. Pin
Naveenvenk25-Feb-14 7:07
Naveenvenk25-Feb-14 7:07 
AnswerRe: takes too long to run android simulator, looking for alternatives. Pin
Kornfeld Eliyahu Peter26-Feb-14 5:29
professionalKornfeld Eliyahu Peter26-Feb-14 5:29 
AnswerRe: takes too long to run android simulator, looking for alternatives. Pin
Peter Leow1-Mar-14 3:34
professionalPeter Leow1-Mar-14 3:34 
AnswerRe: takes too long to run android simulator, looking for alternatives. Pin
Member 105770039-Mar-14 8:15
Member 105770039-Mar-14 8:15 
QuestionAndroid AsynkTask Taking too Long Rotating Progress Dialog Pin
Cyber1221-Feb-14 21:38
Cyber1221-Feb-14 21:38 
AnswerRe: Android AsynkTask Taking too Long to respond Pin
Cyber1221-Feb-14 23:13
Cyber1221-Feb-14 23:13 
AnswerRe: Android AsynkTask Taking too Long Rotating Progress Dialog Pin
BupeChombaDerrick9-Mar-14 1:01
BupeChombaDerrick9-Mar-14 1:01 
QuestionAndroid Sync Adapter Xamarin Pin
Naga Suresh18-Feb-14 1:13
Naga Suresh18-Feb-14 1:13 
AnswerRe: Android Sync Adapter Xamarin Pin
Ahmed Bensaid26-Feb-14 2:17
professionalAhmed Bensaid26-Feb-14 2:17 
AnswerRe: Call blocking Pin
Peter Leow16-Feb-14 13:26
professionalPeter Leow16-Feb-14 13:26 
SuggestionRe: Call blocking Pin
Richard MacCutchan16-Feb-14 22:58
mveRichard MacCutchan16-Feb-14 22:58 
GeneralRe: Call blocking Pin
Tom Marvolo Riddle16-Feb-14 23:19
professionalTom Marvolo Riddle16-Feb-14 23:19 
QuestionRe: Call blocking Pin
thatraja16-Feb-14 23:40
professionalthatraja16-Feb-14 23:40 
AnswerRe: Call blocking Pin
Richard MacCutchan17-Feb-14 0:37
mveRichard MacCutchan17-Feb-14 0:37 
GeneralRe: Call blocking Pin
Richard Deeming17-Feb-14 2:09
mveRichard Deeming17-Feb-14 2:09 
GeneralRe: Call blocking Pin
Richard MacCutchan17-Feb-14 2:32
mveRichard MacCutchan17-Feb-14 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.