Thank you so much for your help I really appreciate it.
I face another problem when I reach the last nested activity with the
tab
activity. so when I press on one of the tab(Branch Search) it takes me
to a page when I have a edittext and go button when I press the go
button to get the locations of the specific zipcode, I get the
locations with the tab bar, but when I press the location tab bar in
the location results page
again it shows me the location results intsted of the edittext with
the go button
any suggestion to fix this problem
you already see the code of the three classes and below is the
LocationSearchResults where I have the problem
package IAA.IAAProject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import IAA.IAAProject.R;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
public class LocationSearchResults extends Activity
{
private TextView txtData;
//private EditText editText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationsearchresults);
txtData = (TextView) findViewById(R.id.txtData);
Bundle bundle = this.getIntent().getExtras();
String zipCode = bundle.getString("zipCode").trim();
String url = "https://........ ";
url += zipCode;
connect(url);
}
private String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}
/* This is a test function which will connects to a given
* rest service and prints it's response to Android Log with
* labels "Praeda".
*/
public void connect(String url)
{
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet(url);
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
// Examine the response status
// Get hold of the response entity
HttpEntity entity = response.getEntity();
// If the response does not enclose an entity,
there is no need
// to worry about connection release
if (entity != null) {
// A Simple JSON Response Read
InputStream instream =
entity.getContent();
String result=
convertStreamToString(instream);
JSONArray entries = new
JSONArray(result);
String output = "";
for(int i=0;i<entries.length();i++)
{
JSONObject jobj =
entries.getJSONObject(i);
output+="------------\n";
output += "branchCity : " +
jobj.getString("branchCity") + "\n
output += "branchDistanceRank : " +
jobj.getString("branchDistanceRank") + "\n";
output += "branchFax : " +
jobj.getString("branchFax") + "\n";
output += "branchName : " +
jobj.getString("branchName") + "\n";
output += "branchPhone: " +
jobj.getString("branchPhone") + "\n";
output += "branchState : " +
jobj.getString("branchState") + "\n
\n";
}
txtData.setText(output);
// Closing the input stream will
trigger connection release
instream.close();
}
else
Toast.makeText(getBaseContext(), " the
entity is equals to null",
Toast.LENGTH_LONG).show();
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
txtData.setText("Error w/file: " +
e.getMessage());
e.printStackTrace();
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I beleive I should add some code after txtData.setText(output);
Thank you in advance for your help
On Jul 4, 4:11 am, Jastp <[email protected]> wrote:
> Hi......
> The reason behind getting null ptr exce. is simple..
> replace the class "BranchSearch" by "BranchSearchHelper" in your
> MainActivity's OnCreate->
>
> intent = new Intent().setClass(this, BranchSearch.class);
> replace it by:
> intent = new Intent().setClass(this, BranchSearchHelper.class);
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en