2

これが私のコードです:

String str = "just_a_string";
System.out.println("]" + str + "[");
System.out.println("]" + str.replace("", "") + "[");
System.out.println("]" + str.substring(5) + "[");
System.out.println("]" + str.substring(5).replace("", "") + "[");
System.out.println("]" + str.substring(3, 8) + "[");
System.out.println("]" + str.substring(3, 8).replace("", "") + "[");
System.out.println("]" + "sdajndan".substring(5).replace("", "") + "[");

そしてここに出力があります

05-09 19:09:20.570: I/System.out(23801): ]just_a_string[
05-09 19:09:20.570: I/System.out(23801): ]just_a_string[
05-09 19:09:20.570: I/System.out(23801): ]a_string[
05-09 19:09:20.570: I/System.out(23801): ]a_s[      **
05-09 19:09:20.570: I/System.out(23801): ]t_a_s[
05-09 19:09:20.570: I/System.out(23801): ]t_[       **
05-09 19:09:20.570: I/System.out(23801): ][         **

明らかに、** でマークされた行は予期しないものです。

この問題は、私の Android フォン A (LG P920 Optimus 3D、Android 2.3.3) で発生します。AndroidフォンB(LG E720 Optimus Chic、Android 2.2)でテストしているときに停止します。無限ループに陥ると思います。

Java1.51.6. どちらもそれぞれ同じ動作になります。

私はまた、Javaプロジェクトを使用して同じEclipseでテストました. 予想どおり、すべての出力が正しいです。1.51.61.7

String.replace(“”, “”)これは、文字列のバッキング配列に対して実装するデバイス固有の問題である可能性があります。

あなたのデバイスでテストするのを手伝ってくれませんか?

String.replace(CharSequence, CharSequence)メソッドの Android ソース コードを教えてください。(docjarのように)

どうもありがとう!


コードを少し変更したので、Android デバイスでも表示できます。(とにかく同じコードです)。

携帯電話 A と携帯電話 B の両方でテストしました。前述のように、動作は同じです。

package com.example.testprojectnew;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

    String output_text = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String str = "just_a_string";
        process("1]" + str + "[");
        process("2]" + str.replace("", "") + "[");
        process("3]" + str.substring(5) + "[");
        process("4]" + str.substring(5).replace("", "") + "[");
        process("5]" + str.substring(3, 8) + "[");
        process("6]" + str.substring(3, 8).replace("", "") + "[");
        process("7]" + "sdajndan".substring(5).replace("", "") + "[");

        output_text = output_text.concat("\n\nLines (1 & 2), (3 & 4), (5 & 6), should be the same.");

        ((TextView) findViewById(R.id.a_string)).setText(output_text);
    }
    private void process(String str) {
        System.out.println(str);
        output_text = output_text.concat(str).concat("\n");
    }
}
4

1 に答える 1