Click here to Skip to main content
15,889,281 members
Home / Discussions / Android
   

Android

 
GeneralRe: Replacement of depracted interface in android Pin
aahamdan4-Jul-16 10:34
aahamdan4-Jul-16 10:34 
GeneralRe: Replacement of depracted interface in android Pin
David Crow4-Jul-16 15:51
David Crow4-Jul-16 15:51 
GeneralRe: Replacement of depracted interface in android Pin
Richard MacCutchan4-Jul-16 21:20
mveRichard MacCutchan4-Jul-16 21:20 
QuestionAndroid OCR Pin
Member 1131712230-Jun-16 3:12
Member 1131712230-Jun-16 3:12 
AnswerRe: Android OCR Pin
David Crow30-Jun-16 4:46
David Crow30-Jun-16 4:46 
GeneralRe: Android OCR Pin
Member 113171221-Jul-16 2:02
Member 113171221-Jul-16 2:02 
QuestionRe: Android OCR Pin
David Crow1-Jul-16 8:57
David Crow1-Jul-16 8:57 
QuestionNull Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task Pin
ahmed_sa22-Jun-16 12:28
ahmed_sa22-Jun-16 12:28 
I designed app to make order for pizza food restaurant
I show userid,menu id ,address,longtiude,latitude then press on button make order
Error show after I press button and found in async task doin background
It give me fatal exception error
An error occurred while executing doInBackground()
and it show to me two lines have proplem
AddNewOrder.doInBackground(Summary.java:113)
AddNewOrder.doInBackground(Summary.java:77)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.json.JSONObject.getBoolean(java.lang.String)' on a null object reference
package com.pizza_final_project_app.pizza_final_project;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class Summary extends Activity {
SharedPreferences preferences;
private ProgressDialog pDialog;
//JSONParser jsonParser = new JSONParser();
boolean errorFound;
TextView textaddress;
TextView textlongtiude;
TextView textlatitude;
TextView text2;
TextView textuser;
Button btnorder;
private static final String TAG_SUCCESS = "success";
private static final String TAG = Summary.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_summary);
text2=(TextView)findViewById(R.id.textView3);
textaddress=(TextView)findViewById(R.id.textaddress);
textuser=(TextView)findViewById(R.id.textView4);
textlongtiude=(TextView)findViewById(R.id.textlongtiude);
textlatitude=(TextView)findViewById(R.id.textlatitude);
Intent i = getIntent();
String id = i.getStringExtra("Data4");
String address = i.getStringExtra("Data8");
String longtiude = i.getStringExtra("Data9");
String latitude = i.getStringExtra("Data10");
text2.setText(id);
textaddress.setText(address);
textlongtiude.setText(longtiude);
textlatitude.setText(latitude);
preferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

String email=preferences.getString("email","");
textuser.setText(email);
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
btnorder=(Button)findViewById(R.id.button2);
btnorder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
addOrder(textuser.getText().toString().trim(), text2.getText().toString().trim(),
textaddress.getText().toString().trim(), textlongtiude.getText().toString().trim(),
textlatitude.getText().toString().trim());

}
});


}
//line 77
class AddNewOrder extends AsyncTask<string, string,="" string=""> {

@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Summary.this);
pDialog.setMessage("Making Order...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

protected String doInBackground(String... args) {
final JSONParser jsonParser = new JSONParser();
// Building Parameters
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("userID", args[0]));
params.add(new BasicNameValuePair("menuID", args[1]));
params.add(new BasicNameValuePair("address", args[2]));
params.add(new BasicNameValuePair("longitude", args[3]));
params.add(new BasicNameValuePair("latitude", args[4]));


JSONObject jObj = jsonParser.makeHttpRequest(AppConfig.URL_Order,
"POST", params);

try {
//Line 113
boolean error = jObj.getBoolean("error");
if (!error) {

errorFound=false;
} else {
errorFound=true;

}
} catch (JSONException e) {
e.printStackTrace();
}

return null;
}
protected void onPostExecute(String file_url) {
if (pDialog.isShowing()) {
pDialog.dismiss();
if (!errorFound){
Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();


Intent intent = new Intent(
Summary.this,
FinalResult.class);
startActivity(intent);
finish();
}
else{
Toast.makeText(getApplicationContext(), "An Error occoured!", Toast.LENGTH_LONG).show();

}
}
}

}
*/
private void addOrder(final String userID, final String menuID, final String address,
final String longitude, final String latitude) {

new AddNewOrder().execute(userID, menuID, address, longitude, latitude);

}

}



Class AppConfig
package com.pizza_final_project_app.pizza_final_project;

public class AppConfig {

public static String URL_Order = "http://amit-learning.com/myPizza/Api_v2.php?functi...";

json parser
package com.pizza_final_project_app.pizza_final_project;

import android.util.Log;

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 java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

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;
Log.d("data",url);
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();
Log.d("json","data is "+json);

} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}
}
AnswerRe: Null Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task Pin
David Crow22-Jun-16 16:47
David Crow22-Jun-16 16:47 
GeneralRe: Null Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task Pin
ahmed_sa22-Jun-16 18:49
ahmed_sa22-Jun-16 18:49 
GeneralRe: Null Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task Pin
Nelek4-Aug-16 4:24
protectorNelek4-Aug-16 4:24 
AnswerRe: Null Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task Pin
Richard MacCutchan22-Jun-16 22:08
mveRichard MacCutchan22-Jun-16 22:08 
QuestionCannot create android application in eclipse. Pin
AkhilSreekar19-Jun-16 9:31
AkhilSreekar19-Jun-16 9:31 
AnswerRe: Cannot create android application in eclipse. Pin
Richard MacCutchan19-Jun-16 21:50
mveRichard MacCutchan19-Jun-16 21:50 
QuestionUnfortunately this app has stopped working Pin
Member 1047665818-Jun-16 16:21
Member 1047665818-Jun-16 16:21 
AnswerRe: Unfortunately this app has stopped working Pin
wseng4-Jul-16 20:37
wseng4-Jul-16 20:37 
Questionsome app can't killBackgroundProcesses Pin
Member 1257783610-Jun-16 23:22
Member 1257783610-Jun-16 23:22 
QuestionRe: some app can't killBackgroundProcesses Pin
David Crow13-Jun-16 1:55
David Crow13-Jun-16 1:55 
QuestionCan't Change Android CalendarView to another month Pin
Member 1242380510-Jun-16 6:45
Member 1242380510-Jun-16 6:45 
AnswerRe: Can't Change Android CalendarView to another month Pin
David Crow10-Jun-16 10:03
David Crow10-Jun-16 10:03 
GeneralRe: Can't Change Android CalendarView to another month Pin
Member 1242380510-Jun-16 10:30
Member 1242380510-Jun-16 10:30 
GeneralRe: Can't Change Android CalendarView to another month Pin
David Crow10-Jun-16 10:36
David Crow10-Jun-16 10:36 
QuestionGood ACTIVE Android discussion forum? Pin
Member 1242380510-Jun-16 6:25
Member 1242380510-Jun-16 6:25 
AnswerRe: Good ACTIVE Android discussion forum? Pin
Richard MacCutchan10-Jun-16 6:32
mveRichard MacCutchan10-Jun-16 6:32 
GeneralRe: Good ACTIVE Android discussion forum? Pin
Member 1242380510-Jun-16 6:41
Member 1242380510-Jun-16 6:41 

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.