the EXCEPETION show
IOEXCEPETION
e.getMessage()= unknow error
Could someone help me to solve this problem? thanks
Using java Syntax Highlighting
- package mis.NewServlet;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.TextView;
- public class NewServlet extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button goButton = (Button)findViewById(R.id.go);
- goButton.setOnClickListener(mGoListener);
- }
- //load data from txtFile
- private OnClickListener mGoListener = new OnClickListener()
- {
- public void onClick(View v)
- {
- try {
- URL myURL = new URL("http://jimjim.no-ip.org:8080/testDataEn.txt");
- URLConnection ucon = myURL.openConnection();
- String encoding = "UTF-8";
- TextView result ;
- result = (TextView)findViewById(R.id.text1);
- InputStream is = ucon.getInputStream();
- InputStreamReader isreader = new InputStreamReader(is,encoding);
- BufferedReader br = new BufferedReader(isreader);
- StringBuffer buffer = new StringBuffer();
- String line = "";
- while ((line = br.readLine()) != null){
- buffer.append(line);
- }
- String s1 = ucon.getContentEncoding();
- String s2 = ucon.toString();
- String s3 = buffer.toString();
- String s4 ;
- if(ucon.getDoInput()){
- s4 = "DoInput";
- }
- else{
- s4 = "false";
- }
- result = (TextView)findViewById(R.id.text1);
- result.setText(
- "ucon.getContentEncoding:"+"\n"+s1+"\n"+"\n"+
- "ucon.toString():"+"\n"+s2+"\n"+"\n"+
- "ucon.getDoInput():"+"\n"+s4+"\n"+"\n"+
- "UTF-8encoding:"+"\n"+s3+"\n"+"\n");
- }catch (MalformedURLException e) {
- TextView result = (TextView)findViewById(R.id.text2);
- result.setText("MalformedURLException");
- e.printStackTrace();
- } catch (IOException e) {
- TextView result = (TextView)findViewById(R.id.text2);
- e.printStackTrace();
- result.setText("IOException"+"\n"+e.getMessage()+"\n"+e.getLocalizedMessage());
- e.printStackTrace();
- }catch (Exception e) {
- TextView result = (TextView)findViewById(R.id.text2);
- result.setText("bug!!"+e.getMessage());
- }
- }
- };
- }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


