The import android. App. *;
The import android. OS. *;
The import android. Widget. *;
The import android. Text. *;
The import android. View. The view. *;
The import android. View. *;
The import android. Content. *;
The import android. Util. *;
Public class MainActivity extends the Activity
{EditText so;
Int a, b=0;
The Button so_bu;
Char so_s [] []=new char [20] [10].
Char so_t [] []=new char [1] [10].
String sc=new String (), scan=new String ();
@ Override
Protected void onCreate (Bundle savedInstanceState)
{
So_s [0]="1234". ToCharArray ();
Sc=new String (so_s [0]).
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Main);
So=(EditText) the findViewById (R.i d.m ain_so);
So. AddTextChangedListener (new TextWatcher () {
Public void beforeTextChanged (CharSequence s, int a, b int, int) c {
}
Public void onTextChanged (CharSequence s, int a, b int, int) c {
Scan=s.t oString ();
//Toast. MakeText (MainActivity. This, sc, Toast. LENGTH_SHORT), show ();
}
Public void afterTextChanged (the Editable s) {
}
});
So_bu=(Button) the findViewById (R.i d.m ain_button_so);
So_bu. SetOnClickListener (new View. An OnClickListener () {
Public void onClick (View v) {
A=scan. The length ();
Int n=0, I=0, j=0;
So_t [0]=scan. ToCharArray ();
for(i=0; i<20; I++) {
for(j=0; j<10; J++) {
If (so_t [0] [n]==so_s [I] [j]) {
{if (n==a - 1)
B=1;
break;
} the else
N++;
}
}
If (b==1)
break;
}
If (b==1) {
Intent son=new Intent (MainActivity. This, interActivity. Class);
StartActivity (son);
} the else
Toast. MakeText (MainActivity. This, "did not find the conform to the result," Toast. LENGTH_SHORT), show ();
}
});
}
}
Above are some of the code, I write, the effect is in the input box where I enter the results after clicking the button, if there is a consistent text is jump page, and can output, otherwise, did not find the results, but when I enter, if you have what does not conform to the result but no consistent results when it comes to flash back, also did not say that sentence, I don't know why, I baidu for a long time didn't find the answer, ask good intention person to help,
Two picture is run log,
CodePudding user response:
An array, and when you click on the button without input character, scan "" string is empty, so scan. The length ()=0, so you view access so_t [0] [n] would be an errorCodePudding user response:
Public class MainActivity extends the Activity {@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Main);
The EditText so=(EditText) the findViewById (R.i d.m ain_so);
The Button so_bu=(Button) the findViewById (R.i d.m ain_button_so);
So_bu. SetOnClickListener (new View. An OnClickListener () {
Public void onClick (View v) {
If (so the getText (). The toString (). The equals (" 1234 ")) {
Intent son=new Intent (MainActivity. This, interActivity. Class);
StartActivity (son);
} else {
Toast. MakeText (MainActivity. This, "did not find the conform to the result," Toast. LENGTH_SHORT), show ();
}
}
});
}
}
CodePudding user response:
The defined array in several assignment again, not only change its value, and change its length, so the for loop subscript crossing the line would appear,Roughly looked at do you want to compare the values of the two strings is the same, the second floor reply referred to in the equals method is better,
CodePudding user response: