发布'č','š'和'ž'后应用关闭

时间:2014-07-10 08:44:21

标签: android

发布包含'č','š'和'ž'等字符的单词时遇到问题。这些角色都在Android键盘中。调用startActivity(Jsoup_result)后,应用程序崩溃了。而textview也不显示这个字符。它只显示 。起初它甚至不会检测它们,只会留下一个空白区域(使用UTF-8参数返回 字符)。

起初我认为这个问题只与textview有关。当我输入这个字符时,应用程序就会关闭(它并没有说应用程序已停止工作)。也没有错误。

protected String doInBackground(String... params) {

    String url = "http://www.ap-ljubljana.si/vozni_red2/VR2.php";
    HttpPost post = new HttpPost(url);
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();

    parameters.add(new BasicNameValuePair("VSTOP_IME", vhod));
    parameters.add(new BasicNameValuePair("IZSTOP_IME", izhod));

    try {
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters);
        HttpClient client = new DefaultHttpClient();
        post.setEntity(entity);
        HttpResponse response = client.execute(post);
        html_response = EntityUtils.toString(response.getEntity(), UTF-8);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }


    return null;
}
    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);

        Intent Jsoup_result = new Intent(getActivity(), HtmlCode.class);
        Jsoup_result.putExtra("html", html_response);
        startActivity(Jsoup_result);
    }

}

以下是活动中显示Jsoup

解析结果的代码
public class HtmlCode extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String value = intent.getStringExtra("html");
    setContentView(R.layout.htmlkoda);
    TextView tv_html = (TextView) findViewById(R.id.tv_html);


    Document document = Jsoup.parse(value);
    Elements tr = document.select("select[name=VSTOP_ID]");
    Elements options = tr.select("select > option");
    value = "";

    for(Element element : options)
    {
        value += element.text() + "\n";
    }

    tv_html.setText(value);

}

}

logcat的

07-10 07:44:21.059    1110-1110/com.example.blaz.pager D/InputEventConsistencyVerifier﹕ KeyEvent: ACTION_UP but key was not down.
in android.widget.EditText{b3dd0c78 VFED..CL .F...... 12,190-468,249 #7f090004 app:id/ff_izstop}
0: sent at 305638000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=305638, downTime=305546, deviceId=0, source=0x101 }
07-10 07:45:11.629    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_C, scanCode=46, metaState=0, flags=0x8, repeatCount=2, eventTime=356228, downTime=355674, deviceId=0, source=0x101 }
07-10 07:45:11.629    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_C, scanCode=46, metaState=0, flags=0x8, repeatCount=3, eventTime=356337, downTime=355674, deviceId=0, source=0x101 }
07-10 07:45:11.819    1110-1110/com.example.blaz.pager W/EGL_emulation﹕ eglSurfaceAttrib not implemented
07-10 07:45:11.879    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_C, scanCode=46, metaState=0, flags=0x8, repeatCount=4, eventTime=356388, downTime=355674, deviceId=0, source=0x101 }
07-10 07:45:11.899    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_C, scanCode=46, metaState=0, flags=0x8, repeatCount=5, eventTime=356440, downTime=355674, deviceId=0, source=0x101 }
07-10 07:45:11.899    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_C, scanCode=46, metaState=0, flags=0x8, repeatCount=6, eventTime=356610, downTime=355674, deviceId=0, source=0x101 }
07-10 07:45:12.149    1110-1110/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 164K, 6% free 3920K/4164K, paused 51ms, total 59ms
07-10 07:45:17.289    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_Z, scanCode=44, metaState=0, flags=0x8, repeatCount=2, eventTime=361978, downTime=361423, deviceId=0, source=0x101 }
07-10 07:45:17.419    1110-1110/com.example.blaz.pager W/EGL_emulation﹕ eglSurfaceAttrib not implemented
07-10 07:45:17.459    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_Z, scanCode=44, metaState=0, flags=0x8, repeatCount=3, eventTime=362029, downTime=361423, deviceId=0, source=0x101 }
07-10 07:45:17.469    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_Z, scanCode=44, metaState=0, flags=0x8, repeatCount=4, eventTime=362080, downTime=361423, deviceId=0, source=0x101 }
07-10 07:45:17.479    1110-1110/com.example.blaz.pager W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_Z, scanCode=44, metaState=0, flags=0x8, repeatCount=5, eventTime=362187, downTime=361423, deviceId=0, source=0x101 }
07-10 07:45:23.049    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 281K, 9% free 4127K/4492K, paused 54ms, total 55ms
07-10 07:45:23.769    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 381K, 15% free 4034K/4692K, paused 70ms, total 71ms
07-10 07:45:23.769    1110-1124/com.example.blaz.pager I/dalvikvm-heap﹕ Grow heap (frag case) to 4.265MB for 262160-byte allocation
07-10 07:45:23.839    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 128K, 16% free 4162K/4952K, paused 60ms, total 60ms
07-10 07:45:24.099    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 36K, 16% free 4162K/4952K, paused 56ms, total 56ms
07-10 07:45:24.099    1110-1124/com.example.blaz.pager I/dalvikvm-heap﹕ Grow heap (frag case) to 4.640MB for 524304-byte allocation
07-10 07:45:24.169    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 256K, 20% free 4418K/5468K, paused 47ms, total 47ms
07-10 07:45:24.509    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 61K, 20% free 4418K/5468K, paused 52ms, total 52ms
07-10 07:45:24.509    1110-1124/com.example.blaz.pager I/dalvikvm-heap﹕ Grow heap (frag case) to 5.390MB for 1048592-byte allocation
07-10 07:45:24.599    1110-1124/com.example.blaz.pager D/dalvikvm﹕ GC_FOR_ALLOC freed 512K, 25% free 4930K/6496K, paused 48ms, total 48ms
07-10 07:45:26.249    1110-1110/com.example.blaz.pager W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection

String vhod被定义为“Ljubljana”,izhod被定义为“Čatež”

1 个答案:

答案 0 :(得分:0)

html_response = EntityUtils.toString(response.getEntity(), UTF-8);

那不编译。你了:

html_response = EntityUtils.toString(response.getEntity(), "UTF-8");

但随着网站的推出

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">

你最好使用

html_response = EntityUtils.toString(response.getEntity());

我刚在textView中的onPostExecute中显示了html_response。对我而言看起来还不错。

<强>更新

在更好地意识到必须完成Windows-1250的某些功能后,我尝试了

html_response = EntityUtils.toString(response.getEntity(), "windows-1250");

而且......宾果!这些字符现在与使用浏览器发布时相同。