Home > Mobile >  For bosses to help solve some of the android.
For bosses to help solve some of the android.

Time:10-13

Package com. Instruction;

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 error

CodePudding 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:

reference m - 1/f, oj response:
an array, and when you click on the button without input character, scan "" string is empty, so scan. The length ()=0, so your view to obtain so_t [0] [n] would be an error

Then how to solve?

CodePudding user response:

Numerical cross-border, 51 line errors

CodePudding user response:

Java. Lang. ArrayIndexOutOfBoundsException: length=0; The index=0

An array
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++;
}
}

So_s [I] [j], you set the Max, j can be 9, however your so_s maximum length is 4 "so_s [0]=" 1234 ". ToCharArray ();"
So you input error so_s [I] [j] error

When you enter nothing so_t [0]=scan. ToCharArray (); There is no data, length of 0, so so_t [0] [n] error


Note: so_s [0]="1234". ToCharArray (); Said you define so_s [0] 10 the length of the array to replace in order to "1234". ToCharArray () four
the length of the array

You can change to:


//need so_s [0] greater than or equal to the length of the "1234". ToCharArray (). The length is not an array error
for(int i=0; I<" 1234 ". ToCharArray (). The length; I++) {
So_s [0] [I]="1234". ToCharArray () [I];
}
Then
If (so_t [0]. Length> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related