0

I'm trying to make a user profile page.

I have done some hard work and managed to retrieve the json objects and store user data in sql database and display these data (string) into TextView such as name and email which works fine.

I also have the URLs to users photos in the same database but I can't retrieve the URL and display on the ImageView just like the other text string..

Could someone kindly show me how to tweak this code to do that?

Please consider this from a Java newbie. Thank you! ^^

public class DirectoryDetailMeActivity extends Activity {

String eid; //user ID

JSONParser jsonParser = new JSONParser();

private static final String url_veiw_directory = "http://www.myweb.com/android/include/directory_detail_me.php";

private static final String TAG_ID = "eid";
private static final String TAG_IMG = "photo"; 
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";    

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);         
setContentView(R.layout.directory_detail_me);

new GetDirectoryDetails().execute();

}

class GetDirectoryDetails extends AsyncTask<String, String, String> {

protected String doInBackground(String... params) {     

runOnUiThread(new Runnable() {
    public void run() {

    int success;
        try {

        List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("id", eid));

            JSONObject json = jsonParser.makeHttpRequest(url_veiw_directory, "GET", params);

            Log.d("my profile", json.toString());

            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {

            JSONArray directoryObj = json.getJSONArray(TAG_DIRECTORY); 
            JSONObject directory = directoryObj.getJSONObject(0);

            // It works fine if I give the URL manually. 
            String imageURL = "";

            ImageView imagePhoto = (ImageView) findViewById(R.id.photo);    

            ImageLoader imgLoader = new ImageLoader(getApplicationContext());        
            imgLoader.DisplayImage(imageURL, imagePhoto);

            TextView txtName = (TextView) findViewById(R.id.name);
            TextView txtEmail = (TextView) findViewById(R.id.email);                    

            txtName.setText(directory.getString(TAG_NAME));
            txtEmail.setText(directory.getString(TAG_EMAIL));

            }else{

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

    }

}
4
  • Shouldn't be imageURL = directory.getString(TAG_IMG) somewhere? Is it the problem, or is the imageLoader? Commented Nov 16, 2012 at 15:49
  • you meant? String imageURL = directory.getString(TAG_IMG); Commented Nov 16, 2012 at 15:54
  • When you do String imageURL = directory.getString(TAG_IMG); your string is null? If so, can you try to log your json string? Commented Nov 16, 2012 at 15:56
  • @Zoleas, I'm not sure what happen but it displays blank field including the name and email.. Commented Nov 16, 2012 at 15:57

1 Answer 1

4

You need to fill imageURL with getting url from JSONObject. I think JSONObject has image array.

try firstly try this.

  String imageURL = directory.getString(TAG_IMG);
  //then
  ImageView imagePhoto = (ImageView) findViewById(R.id.photo);    
  ImageLoader imgLoader = new ImageLoader(getApplicationContext());        
  imgLoader.DisplayImage(imageURL, imagePhoto);

if it doesn't work

 JSONArray imageObj = directory.getJSONArray(TAG_IMG); 
 JSONObject img = imageObj.getJSONObject(0);
 String imageURL = img.getString("NewTAG");
  //then
 ImageView imagePhoto = (ImageView) findViewById(R.id.photo);    
 ImageLoader imgLoader = new ImageLoader(getApplicationContext());        
 imgLoader.DisplayImage(imageURL, imagePhoto);

if both of them useless. In ImageLoder class change this line

 InputStream is = (InputStream) new URL(url).getContent();

to this

 InputStream is = (InputStream) new URL(url).openConnection().getInputStream();
Sign up to request clarification or add additional context in comments.

8 Comments

@Bans, thank you for helping me on this. unfortunately, the both didn't work. It displays blank content including the name and email filed..
try debug mode and look at your directory json object. maybe this field empty
but i think your jsonobject doesn't have url or contains extra uncessary characters.
do You use github.com/thest1/LazyList library? it also needs permission WriteExternalStorage :).
yes i do have that in Manifest.. thank you for helping me kindly
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.