所以我在Android工作室使用“andy模拟器”运行我的调试器,它几乎与Android工作室的android模拟器相同,然后我收到了运行时错误 11-01 13:56:57.796 8967-8976 /? I / AndroidRuntime:注意:附加线程'Binder_1'失败 11-01 13:56:58.530 8997-9006 /? I / AndroidRuntime:注意:附加线程'Binder_2'失败 所以请问如何解决? 我不知道这是否会有所帮助,但是当我在bluestacks上运行我的应用程序时,它会冻结屏幕冻结,按钮不再可点击,之后我点击它,它不会崩溃它冻结:)。
如果有帮助,这是我的代码:
package com.example.android.quizgenerator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import static android.R.attr.x;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Print(View view)
{
//get the text
EditText nameField = (EditText) findViewById(R.id.fill_here);
Editable text_ar = nameField.getText();
String s = text_ar.toString(); //this is the string that is going to be cut
String s2 = ""; //this is the final string
String MyText = ""; //this is the stringwhere we accumulate characters
String x, x1, x2, x3, x4 = "";
//the counter i, the check if !=a,an,the variable t
int n = 0;
int i = 0;
int t = 0;
//Edit the text
//add the word the translation of X is
while (!(s.equals(""))) {
//only assign this value if the charAt(i) exists
if (s.length() != 0)
x = s.charAt(i) + "";
else
x = "";
if (s.length() > 1) {
x1 = s.charAt(i + 1) + "";
} else
x1 = "";
if (s.length() > 2) {
x2 = s.charAt(i + 2) + "";
} else
x2 = "";
if (s.length() > 3) {
x3 = s.charAt(i + 3) + "";
} else
x3 = "";
if (s.length() > 4) {
x4 = s.charAt(i + 4) + "";
} else
x4 = "";
MyText = MyText + s.charAt(i);
//we should have space the space to enter here
if (x.equals(" ") && x1.equals("t") && x2.equals("h") && x3.equals("e") && x4.equals(" ")) {
//get Mytext and update s
s = s.replace("the ", ""); //deletes 'the ' from s
if (s.indexOf(" ") != -1) {
n = s.indexOf(" "); //index of the end of MyText
MyText = s.substring(0, n);//gets the word after 'the ' that was just deleted and supposing that there's a space
//to determine the end of MyText: no space no more words
} else {
MyText = s.substring(0, s.length());//there's no space to determine the end of MyText
// which means it is the end of the sentence: no space no more words
}
s = s.replace(MyText, ""); //gets s Minus MyText and keep the space after MyText
MyText = "the translation of the " + MyText + " is"; //added the sentence in the beginning
s2 = s2 + "/n" + MyText; //accumulated all the words in a text
t++;
MyText = "";
//delete the string space the space
}
//we should have space an space to enter here
if (x.equals(" ") && x1.equals("a") && x2.equals("n") && x3.equals(" ")) {
//get Mytext and update s
s = s.replace("an ", ""); //deletes 'the ' from s
if (s.indexOf(" ") != -1) {
n = s.indexOf(" "); //index of the end of MyText
MyText = s.substring(0, n);//gets the word after 'the ' that was just deleted and supposing that there's a space
//to determine the end of MyText: no space no more words
} else {
MyText = s.substring(0, s.length());//there's no space to determine the end of MyText
// which means it is the end of the sentence: no space no more words
}
s = s.replace(MyText, ""); //gets s Minus MyText and keep the space after MyText
MyText = "the translation of an " + MyText + " is"; //added the sentence in the beginning
s2 = s2 + "/n" + MyText; //accumulated all the words in a text
t++;
MyText = "";
}
//we should have space a space to enter here
if (x.equals(" ") && x1.equals("a") && x2.equals(" ")) {
//get Mytext and update s
s = s.replace("a ", ""); //deletes 'the ' from s
if (s.indexOf(" ") != -1) {
n = s.indexOf(" "); //index of the end of MyText
MyText = s.substring(0, n);//gets the word after 'the ' that was just deleted and supposing that there's a space
//to determine the end of MyText: no space no more words
} else {
MyText = s.substring(0, s.length());//there's no space to determine the end of MyText
// which means it is the end of the sentence: no space no more words
}
s = s.replace(MyText, ""); //gets s Minus MyText and keep the space after MyText
MyText = "the translation of a " + MyText + " is"; //added the sentence in the beginning
s2 = s2 + "/n" + MyText; //accumulated all the words in a text
t++;
MyText = "";
}
//we should have space anyletter!=the,a,an
if (x.equals(" ") && (t == 0)) //this is a word
{
//get Mytext and update s
s = s.replace(" ", ""); //deletes 'the ' from s
if (s.indexOf(" ") != -1) {
n = s.indexOf(" "); //index of the end of MyText
MyText = s.substring(0, n);//gets the word after 'the ' that was just deleted and supposing that there's a space
//to determine the end of MyText: no space no more words
} else {
MyText = s.substring(0, s.length());//there's no space to determine the end of MyText
// which means it is the end of the sentence: no space no more words
}
s = s.replace(MyText, ""); //gets s Minus MyText and keep the space after MyText
MyText = "the translation of " + MyText + " is"; //added the sentence in the beginning
s2 = s2 + "/n" + MyText; //accumulated all the words in a text
MyText = "";
}
}
//Print the new text
TextView y = (TextView) findViewById(R.id.print_here);
y.setText(s2);
}
}
当我试图解决这个问题时,我发现了第二个问题: 为什么Android应用程序会冻结?
所以当我有一个无限循环时,我发现了问题 我的应用程序Android应用程序的反应是冻结。
答案 0 :(得分:0)
为什么Android应用程序冻结
所以我发现问题似乎当我在我的应用程序中有一个无限循环时,android应用程序对此的反应是冻结。