无法运行我的Android应用程序,无法连接到Web服务
public class Rgister extends Activity {
private Spinner spinner1, spinner2, spinner3, spinner4;
public static String res="";
private Button mButton;
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static Random rnd = new Random();
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
ImageView v = (ImageView) findViewById(R.id.image_2);
v.setImageResource(R.drawable.logo_);
new GetData("","feri").execute();
}
}
答案 0 :(得分:0)
和GetData类:
class GetData extends AsyncTask {
private String Link = "";
private String User = "";
public GetData(String link, String user) {
Link = link;
User = user;
}
@Override
protected String doInBackground(Object[] params) {
try {
String data= URLEncoder.encode("user", "UTF8")+"="+URLEncoder.encode(User,"UTF8");
URL mylink = new URL(Link);
URLConnection connect = mylink.openConnection();
connect.setDoOutput(true);
OutputStreamWriter wr=new OutputStreamWriter(connect.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader reader = new BufferedReader(
new InputStreamReader(connect.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append("line");
}
Rgister.res=sb.toString();
} catch (Exception e) {
}
return "";
}
}