I'm trying to retrieve a specific string on my site. http://plpemag.byethost31.com/functions.php?action=printSpecificArticle&articleid=2
through android and display it on my textview. But when I run the program, the textView is still blank. What might be the problem for this?
GetMethodEx.java
package com.example.navigationdrawerexample;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class GetMethodEx {
public String getInternetData() throws Exception{
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://plpemag.byethost31.com/functions.php?action=printSpecificArticle&articleid=2");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) !=null){
sb.append(l+nl);
}
in.close();
data = sb.toString();
return data;
}finally{
if (in != null){
try{
in.close();
return data;
} catch (Exception e){
e.printStackTrace();
}
}
}
}
}
CollegeBulletinListFragment.java
package com.example.navigationdrawerexample;
import android.app.Fragment;
import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class CollegeBulletinListFragment extends Fragment{
public CollegeBulletinListFragment(){
}
TextView kem;
TextView tester;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_collegebulletinlist, container, false);
kem = (TextView) rootView.findViewById(R.id.angkembular);
tester = (TextView) rootView.findViewById(R.id.tester);
Bundle bun = getArguments();
setTextAndColorsToHead(bun.getString("passingWord"));
GetMethodEx gm = new GetMethodEx();
String returned;
try {
returned = gm.getInternetData();
tester.setText(returned);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rootView;
}
public void setTextAndColorsToHead(String arg){
if (arg.equals("GN")){
kem.setText("General News");
} else if (arg.equals("CCS")){
kem.setText("College of Computer Studies");
} else if (arg.equals("COE")){
kem.setText("College of Engineering");
} else if (arg.equals("COED")){
kem.setText("College of Education");
} else if (arg.equals("CON")){
kem.setText("College of Nursing");
} else if (arg.equals("CBA")){
kem.setText("College of Business and Accountancy");
} else if (arg.equals("CAS")){
kem.setText("College of Arts and Sciences");
} else if (arg.equals("CIHM")){
kem.setText("College of International and Hospitality Management");
}
}
}