java.lang.ClassCastException: org.ksoap2.serialization.SoapObject in android - java

Hi i have developed one android application.
The app purpose is retrieve data from mysql database and display in android device.
This is my android code:
public class RetailerActivity extends Activity {
private final String NAMESPACE = "http://ws.testprops.com";
private final String URL = "http://krish.jelastic.servint.net/Retrieve/services/Fetch?wsdl";
private final String SOAP_ACTION = "http://ws.testprops.com/customerData";
private final String METHOD_NAME = "customerData";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");//Result string will split & store in an array
TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
setContentView(tv);
} catch (Exception e) {
e.printStackTrace();
}
}}
If i have to run the app means blank screen only displayed.it is taking too long time nearly 1 hour
also am getting following error on my android console window:
11-05 10:38:27.868: W/System.err(837): java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
11-05 10:38:27.878: W/System.err(837): at com.retailer.client.RetailerActivity.onCreate(RetailerActivity.java:29)
11-05 10:38:27.878: W/System.err(837): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-05 10:38:27.878: W/System.err(837): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-05 10:38:27.878: W/System.err(837): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-05 10:38:27.878: W/System.err(837): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-05 10:38:27.878: W/System.err(837): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-05 10:38:27.878: W/System.err(837): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 10:38:27.878: W/System.err(837): at android.os.Looper.loop(Looper.java:123)
11-05 10:38:27.878: W/System.err(837): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-05 10:38:27.878: W/System.err(837): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 10:38:27.878: W/System.err(837): at java.lang.reflect.Method.invoke(Method.java:521)
11-05 10:38:27.878: W/System.err(837): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-05 10:38:27.878: W/System.err(837): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-05 10:38:27.888: W/System.err(837): at dalvik.system.NativeStart.main(Native Method)
please help me.how can i resolve this error.

Change
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
to
SoapObject response = (SoapObject)envelope.getResponse();

Related

Fragment cannot be cast to android.content.Context

I want to connect my login page to MySQL PHP but I got some error here.
This is my logcat:
807/com.aeu.mlibrary.mlibraryaeu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.aeu.mlibrary.mlibraryaeu, PID: 1807
java.lang.ClassCastException: com.aeu.mlibrary.mlibraryaeu.LoginFragment cannot be cast to android.content.Context
at com.kosalgeek.asynctask.PostResponseAsyncTask.<init>(PostResponseAsyncTask.java:284)
at com.aeu.mlibrary.mlibraryaeu.LoginFragment.onClick(LoginFragment.java:82)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
and this is the error line in my loginFragment.java:
#Override
public void onClick(View v) {
HashMap postData = new HashMap();
postData.put("mobile", "android");
postData.put("txtUsername", etUsername.getText().toString());
postData.put("txtPassword", etPassword.getText().toString());
PostResponseAsyncTask task = new PostResponseAsyncTask(LoginFragment.this, postData);
task.execute("http://10.0.3.2/mlibrary/HTML/login.php");
}
I need your help guys!
Thank you.
Replace LoginFragment.this with getActvity()
PostResponseAsyncTask task = new PostResponseAsyncTask(getActivity(), postData);
Replace LoginFragment.this with getContext() :
PostResponseAsyncTask task = new PostResponseAsyncTask(getContext(), postData);

NullPointerException on onDestroy() method

I got this problem while exiting my app: when You click 'Back' button the LeadBolt ExitAd appears. Then You click 'No' and app exits and toast appears with "This app has stopped."
So, there's something with ad OR it's something with setting MediaPlayer to null.
Code looks like this:
alarm = new MediaPlayer();
...
#Override
public void onPause() {
super.onPause();
if (alarm != null) {
alarm.release();
alarm = null;
}
}
#Override
public void onStop() {
super.onStop();
if (alarm != null) {
alarm.release();
alarm = null;
}
}
public void onDestroy() {
myController.destroyAd();
// myController2.destroyAd();
if (adView != null) {
adView.destroy();
}
super.onDestroy();
if (alarm != null) {
alarm.release();
alarm = null;
}
}
Exception logs:
11-05 11:06:49.130: E/AndroidRuntime(2019): FATAL EXCEPTION: main
11-05 11:06:49.130: E/AndroidRuntime(2019): java.lang.RuntimeException: Unable to destroy activity {com.klangstudios.car_pilot_remote/com.my_company.my_app.MainActivity}: java.lang.NullPointerException
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3451)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3469)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.access$1200(ActivityThread.java:141)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.os.Looper.loop(Looper.java:137)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-05 11:06:49.130: E/AndroidRuntime(2019): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 11:06:49.130: E/AndroidRuntime(2019): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 11:06:49.130: E/AndroidRuntime(2019): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-05 11:06:49.130: E/AndroidRuntime(2019): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-05 11:06:49.130: E/AndroidRuntime(2019): at dalvik.system.NativeStart.main(Native Method)
11-05 11:06:49.130: E/AndroidRuntime(2019): Caused by: java.lang.NullPointerException
11-05 11:06:49.130: E/AndroidRuntime(2019): at com.klangstudios.car_pilot_remote.MainActivity.onDestroy(MainActivity.java:209)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.Activity.performDestroy(Activity.java:5273)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1110)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3438)
11-05 11:06:49.130: E/AndroidRuntime(2019): ... 11 more
Anyone got similar problem?
In your code, you should replace the following:
myController.destroyAd();
with this:
if(myController!= null) {
myController.destroyAd();
}
then try it. You will avoid getting a null pointer exception, because if myController is null, then the program won't be destroying something that doesn't exist

Must implement the interface while implemented this interface in a activity

I have a Main activity. at Main Activity, in Oncreat{}, i creat a fragment with name "ChannelList"
Code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initVtcId();
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentById(android.R.id.tabcontent) == null) {
FragmentTransaction fragmentTransaction = fm.beginTransaction();
ChannelList list = new ChannelList();
//fragmentTransaction.add(android.R.id.content, list);
fragmentTransaction.add(android.R.id.tabcontent, list);
fragmentTransaction.commit();
}
To oder to ChannelList to communicate up to a Activity with name "ChannelActivity". I use a Interface with name "OnListItemSelectedListener " and its method "onListItemSelected" in ChannelList
public class ChannelList extends ListFragment {
private OnListItemSelectedListener mCallback;
public interface OnListItemSelectedListener {
public void onListItemSelected(ListView l, int position);
}
The Fragment ChannelList captures the interface implementation during its onAttach() lifecycle method
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception.
try {
mCallback = (OnListItemSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnListItemSelectedListener");
}
}
the following method in the fragment is called when the user clicks on a list item. The fragment uses the callback interface to deliver the event to the parent activity.
public void onListItemClick(ListView l, View v, int position, long id) {
mCallback.onListItemSelected(l, mChannelAdapter.getItem(position)
.getID());
}
On ChannelActivity, I implement this interface and its method to call a Fragment with name "ChannelDetailFragment"
public class ChannelActivity extends FragmentActivity implements
ChannelList.OnListItemSelectedListener {
private FragmentManager fm;
private Fragment mChannelDetailFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.channel_activity);
fm = getSupportFragmentManager();
Fragment mChannelListFragment = fm
.findFragmentByTag(ChannelList.TAG);
if (mChannelListFragment == null) {
addFragment(new ChannelList(), false,
ChannelList.TAG);
}
}
#Override
public void onListItemSelected(ListView l, int position) {
Bundle args = new Bundle();
args.putInt(ChannelDetailFragment.CHANNEL_ID, position);
mChannelDetailFragment = fm
.findFragmentByTag(ChannelDetailFragment.TAG);
if (mChannelDetailFragment == null) {
mChannelDetailFragment = new ChannelDetailFragment();
}
mChannelDetailFragment.setArguments(args);
addFragment(mChannelDetailFragment, true, ChannelDetailFragment.TAG);
}
I follow this tut at:
http://developer.android.com/training/basics/fragments/communicating.html#Deliver
Unfortunately, I have an error throw from OnAttach{}. I checked my code manytimes but not detect where is incorrect. Sb help me!
10-02 14:07:40.156: E/AndroidRuntime(980): FATAL EXCEPTION: main
10-02 14:07:40.156: E/AndroidRuntime(980): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.channellistfragment/com.example.channellistfragment.MainActivity}: java.lang.ClassCastException: com.example.channellistfragment.MainActivity#a68d01b8 must implement OnListItemSelectedListener
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.os.Handler.dispatchMessage(Handler.java:99)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.os.Looper.loop(Looper.java:137)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-02 14:07:40.156: E/AndroidRuntime(980): at java.lang.reflect.Method.invokeNative(Native Method)
10-02 14:07:40.156: E/AndroidRuntime(980): at java.lang.reflect.Method.invoke(Method.java:511)
10-02 14:07:40.156: E/AndroidRuntime(980): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-02 14:07:40.156: E/AndroidRuntime(980): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-02 14:07:40.156: E/AndroidRuntime(980): at dalvik.system.NativeStart.main(Native Method)
10-02 14:07:40.156: E/AndroidRuntime(980): Caused by: java.lang.ClassCastException: com.example.channellistfragment.MainActivity#a68d01b8 must implement OnListItemSelectedListener
10-02 14:07:40.156: E/AndroidRuntime(980): at com.example.channellistfragment.ChannelList.onAttach(ChannelList.java:79)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:867)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.Activity.performStart(Activity.java:5018)
10-02 14:07:40.156: E/AndroidRuntime(980): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
10-02 14:07:40.156: E/AndroidRuntime(980): ... 11 more
You have 2 activities and add ChannelList fragment to both of them. First one (Main Activity) doesnt implements your callback interface and you get ClassCast exeption.

NullPointerException on TabGroupactivity when setting button typeface

I'm having a little problem with an activity I have loading in a TabGroupActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_profile);
f = new Functions();
String j = f.getUserInfo();
arialFont = Typeface.createFromAsset(this.getAssets(),"Arial.ttf");
username = (TextView)findViewById(R.id.txtProfileName);
firstname = (TextView)findViewById(R.id.txtName);
Address1 = (TextView)findViewById(R.id.txtAdd1);
Cit = (TextView)findViewById(R.id.txtCity);
PostCode = (TextView)findViewById(R.id.txtPost);
Coun = (TextView)findViewById(R.id.txtCountry);
Phon = (TextView)findViewById(R.id.txtPhone);
dob = (TextView)findViewById(R.id.txtDOB);
gender = (TextView)findViewById(R.id.txtGender);
yourDetails = (Button)findViewById(R.id.Button01);
payment = (Button)findViewById(R.id.Button02);
billing = (Button)findViewById(R.id.Button03);
history = (Button)findViewById(R.id.Button04);
yourDetails.setTypeface(arialFont); <-- Null Pointer exception starts here
payment.setTypeface(arialFont);
billing.setTypeface(arialFont);
history.setTypeface(arialFont);
try {
parseData(j);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The error I recieve from the code is this:
02-27 13:22:47.278: E/AndroidRuntime(929): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Ticketline.Ticketline/com.Ticketline.Ticketline.UserProfile}: java.lang.NullPointerException
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1796)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
02-27 13:22:47.278: E/AndroidRuntime(929): at com.Ticketline.Ticketline.TabGroupActivity.startChildActivity(TabGroupActivity.java:61)
02-27 13:22:47.278: E/AndroidRuntime(929): at com.Ticketline.Ticketline.Account.onCreate(Account.java:33)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.Activity.performCreate(Activity.java:4465)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
02-27 13:22:47.278: E/AndroidRuntime(929): ... 18 more
02-27 13:22:47.278: E/AndroidRuntime(929): Caused by: java.lang.NullPointerException
02-27 13:22:47.278: E/AndroidRuntime(929): at com.Ticketline.Ticketline.UserProfile.onCreate(UserProfile.java:83)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.Activity.performCreate(Activity.java:4465)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-27 13:22:47.278: E/AndroidRuntime(929): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
02-27 13:22:47.278: E/AndroidRuntime(929): ... 26 more
I know the issue is with setting the buttons typeface to Arial, the problem is I don't understand why this is an issue. If I comment the setTypeface lines out it works fine and will move onto other activity which do have their button typefaces set within the TabGroupActivity which perplexes me even more.
Top marks for anyone that can explain this to me
Figured the issue out, the coder who worked on this app before me gave the history button the id "btnHistory" instead of "Button04". Naturally this resolved in a null pointer error because the id "Button04" doesn't exist in that activity.

Issue retrieving JSON in Android

I've looked at countless projects and tutorials and haven't been able to figure out why my app is crashing as soon as it is ran. It seems to run fine if i comment out the first line in the try catch "JSONObject dataObject = json.getJSONObject("data");" The JSON that i'm trying to parse is formatted as such:
{"recordcount":3,
"columnlist":"department,emailaddress,firstname,has_photos,job_full_title,job_title,kid,lastname,location,middlename,no_show_photo,phone,school",
"data":
{"department":["Public Safety","Information Technology","Information Technology"],
"emailaddress":["todd.mongeon#wne.edu","amutti#wne.edu","fatemeh.shams#wne.edu"],
"firstname":["Todd","Tony","Toffee"],
"has_photos":["Y","Y","N"],
"job_full_title":["Officer","Director, Administrative Information Systems","Sr.Technical Programmer/Analyst and Integ Specialist"],
"job_title":["Officer","Director, Administrative Information Systems","Sr.Technical Programmer/Analyst and Integ Specialist"],
"kid":[286899,2497,297411],
"lastname":["Mongeon","Mutti","Shams"],
"location":["PS","12 V","12 V"],
"middlename":["A.","M.",""],
"no_show_photo":["","",""],
"phone":["413-782-1207","413-782-1212","413-796-2398"],
"school":["Public Safety Group","Information Technology Group","Information Technology Group"]}}
My program looks like this (please excuse formatting / things that don't need to be there... it needs to be cleaned up from a lot of the things i've tried to get this to work..)
public class Directory_finalActivity extends ListActivity {
public static String url = "http://www1.wne.edu/webservices/directorydemo.cfc?wsdl&method=getEmployees&limit=25&firstname=to&outputtype=JSON";
// JSON array names
private static final String TAG_FIRST = "firstname";
private static final String TAG_LAST = "lastname";
private static final String TAG_SCHOOL = "school";
private static final String TAG_DEPARTMENT = "department";
private static final String TAG_EMAIL = "emailaddress";
private static final String TAG_PHONE = "phone";
private static final String TAG_JOB = "job_title";
private static final String TAG_LOCATION = "location";
//create JSON array
JSONArray firstNames = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
String[] firstNames = null;
try {
// Getting the data object
JSONObject dataObject = json.getJSONObject("data"); //This is the line that seems to be causing the error.
int numResults = json.getInt("recordcount");
/**
JSONArray firstNameArray = dataObject.getJSONArray("firstname");
JSONArray lastNameArray = dataObject.getJSONArray("lastname");
JSONArray schoolArray = dataObject.getJSONArray("school");
JSONArray departmentArray = dataObject.getJSONArray("department");
JSONArray eMailArray = dataObject.getJSONArray("emailaddress");
JSONArray phoneNumberArray = dataObject.getJSONArray("phone");
JSONArray jobTitleArray = dataObject.getJSONArray("job_title");
JSONArray locationArray = dataObject.getJSONArray("location");
//Loop through index of array(s)
for(int i = 0; i <= numResults; i++)
{
//Store value of JSONArray at index "i" into string variables.
String firstName = firstNameArray.getString(i);
String eMail = eMailArray.getString(i);
String phone = phoneNumberArray.getString(i);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_FIRST, firstName);
map.put(TAG_EMAIL, eMail);
map.put(TAG_PHONE, phone);
//add the hashmap to array list.
contactList.add(map);
}*/
}
catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
//ListAdapter adapter = new SimpleAdapter(this, contactList,
// R.layout.list_item,
// new String[] { TAG_FIRST, TAG_EMAIL, TAG_PHONE }, new int[] {
// R.id.name, R.id.email, R.id.mobile });
//setListAdapter(adapter);
}
}
My JSONParser class
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
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;
}
}
I'm probably doing something incredibly stupid here, i'm new to this so give me a break please haha. I appreciate any info that you guys may have for me.
For curiosity sake the end goal is to search the database (first name, last name, school, and department) and put the results into a list view, when clicked on a window will pop up displaying other relevant information with a couple other features.
It seems every example i see the JSON output they receive from the url is formatted much differently, so i'm having trouble getting this done even with the amount of examples available (sorry for re-post).
Once again thank you for any assistance.
EDIT 1:
LOGCAT:
04-17 00:45:35.828: W/System.err(305): java.net.UnknownHostException: api.androidhive.info
04-17 00:45:35.828: W/System.err(305): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
04-17 00:45:35.838: W/System.err(305): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
04-17 00:45:35.838: W/System.err(305): at java.net.InetAddress.getAllByName(InetAddress.java:242)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-17 00:45:35.838: W/System.err(305): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
04-17 00:45:35.838: W/System.err(305): at directory.plus.JSONParser.getJSONFromUrl(JSONParser.java:39)
04-17 00:45:35.838: W/System.err(305): at directory.plus.Directory_finalActivity.onCreate(Directory_finalActivity.java:53)
04-17 00:45:35.849: W/System.err(305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-17 00:45:35.849: W/System.err(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-17 00:45:35.849: W/System.err(305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-17 00:45:35.849: W/System.err(305): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-17 00:45:35.849: W/System.err(305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-17 00:45:35.849: W/System.err(305): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 00:45:35.849: W/System.err(305): at android.os.Looper.loop(Looper.java:123)
04-17 00:45:35.849: W/System.err(305): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-17 00:45:35.849: W/System.err(305): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 00:45:35.849: W/System.err(305): at java.lang.reflect.Method.invoke(Method.java:521)
04-17 00:45:35.858: W/System.err(305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-17 00:45:35.858: W/System.err(305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-17 00:45:35.858: W/System.err(305): at dalvik.system.NativeStart.main(Native Method)
04-17 00:45:35.858: E/Buffer Error(305): Error converting result java.lang.NullPointerException
04-17 00:45:35.868: E/JSON Parser(305): Error parsing data org.json.JSONException: End of input at character 0 of
04-17 00:45:35.868: D/AndroidRuntime(305): Shutting down VM
04-17 00:45:35.868: W/dalvikvm(305): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-17 00:45:35.888: E/AndroidRuntime(305): FATAL EXCEPTION: main
04-17 00:45:35.888: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{directory.plus/directory.plus.Directory_finalActivity}: java.lang.NullPointerException
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.os.Looper.loop(Looper.java:123)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-17 00:45:35.888: E/AndroidRuntime(305): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 00:45:35.888: E/AndroidRuntime(305): at java.lang.reflect.Method.invoke(Method.java:521)
04-17 00:45:35.888: E/AndroidRuntime(305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-17 00:45:35.888: E/AndroidRuntime(305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-17 00:45:35.888: E/AndroidRuntime(305): at dalvik.system.NativeStart.main(Native Method)
04-17 00:45:35.888: E/AndroidRuntime(305): Caused by: java.lang.NullPointerException
04-17 00:45:35.888: E/AndroidRuntime(305): at directory.plus.Directory_finalActivity.onCreate(Directory_finalActivity.java:59)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-17 00:45:35.888: E/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
EDIT 2:
NEW LOGCAT OUTPUT:
04-17 01:26:12.899: E/JSON Parser(548): Error parsing data in JSONParser org.json.JSONException: Value <wddxPacket of type java.lang.String cannot be converted to JSONObject
04-17 01:26:12.899: D/AndroidRuntime(548): Shutting down VM
04-17 01:26:12.899: W/dalvikvm(548): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-17 01:26:12.919: E/AndroidRuntime(548): FATAL EXCEPTION: main
04-17 01:26:12.919: E/AndroidRuntime(548): java.lang.RuntimeException: Unable to start activity ComponentInfo{directory.plus/directory.plus.Directory_finalActivity}: java.lang.NullPointerException
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.os.Looper.loop(Looper.java:123)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-17 01:26:12.919: E/AndroidRuntime(548): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 01:26:12.919: E/AndroidRuntime(548): at java.lang.reflect.Method.invoke(Method.java:521)
04-17 01:26:12.919: E/AndroidRuntime(548): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-17 01:26:12.919: E/AndroidRuntime(548): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-17 01:26:12.919: E/AndroidRuntime(548): at dalvik.system.NativeStart.main(Native Method)
04-17 01:26:12.919: E/AndroidRuntime(548): Caused by: java.lang.NullPointerException
04-17 01:26:12.919: E/AndroidRuntime(548): at directory.plus.Directory_finalActivity.onCreate(Directory_finalActivity.java:59)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-17 01:26:12.919: E/AndroidRuntime(548): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-17 01:26:12.919: E/AndroidRuntime(548): ... 11 more
04-17 01:26:33.279: I/Process(548): Sending signal. PID: 548 SIG: 9
EDIT FINAL: Problem solved:
Needed to take a sub string of the result returned from the html and pass that into a json object
java.net.UnknownHostException: api.androidhive.info
It looks like your app can't access the network. Have you added:
<uses-permission
android:name="android.permission.INTERNET" />
to your code AndroidManifest.xml?

Categories