Question on Android Studio Script.
Can anyone help me with a reason as to why this script makes the app crash?
package ruberduckyandroid.simplepuzzle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Puzzle extends AppCompatActivity {
//get the info
EditText input01 = ( EditText ) findViewById ( R.id.input1 );
EditText input02 = ( EditText ) findViewById ( R.id.input2 );
EditText input03 = ( EditText ) findViewById ( R.id.input3 );
EditText input04 = ( EditText ) findViewById ( R.id.input4 );
EditText input05 = ( EditText ) findViewById ( R.id.input5 );
EditText input06 = ( EditText ) findViewById ( R.id.input6 );
EditText input07 = ( EditText ) findViewById ( R.id.input7 );
EditText input08 = ( EditText ) findViewById ( R.id.input8 );
EditText input09 = ( EditText ) findViewById ( R.id.input9 );
//Button check = ( Button ) findViewById(R.id.check);
Button reset = ( Button ) findViewById(R.id.Reset);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_puzzle);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
reset.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick ( View view ) {
input01.setText ( "" );
input02.setText ( "" );
input03.setText ( "" );
input04.setText ( "" );
input05.setText ( "" );
input06.setText ( "" );
input07.setText ( "" );
input08.setText ( "" );
input09.setText ( "" );
}
}
);
check.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
//process data
int base01 = Integer.valueOf ( input01.getText().toString() );
int base02 = Integer.valueOf ( input02.getText().toString() );
int base03 = Integer.valueOf ( input03.getText().toString() );
int base04 = Integer.valueOf ( input04.getText().toString() );
int base05 = Integer.valueOf ( input05.getText().toString() );
int base06 = Integer.valueOf ( input06.getText().toString() );
int base07 = Integer.valueOf ( input07.getText().toString() );
int base08 = Integer.valueOf ( input08.getText().toString() );
int base09 = Integer.valueOf ( input09.getText().toString() );
base01 = 4;
if ( base01 == result01 ) {
input01.setTextColor(Color.GREEN);
//input02.setTextColor(Color.RED);
}
input01.setTextColor(Color.GREEN);
}
}
);
}
}
And then how do I use the base functions in an if statement without crashing the app, the current if statement I have is crashing the app.
Thanks in advance for any help.
package ruberduckyandroid.simplepuzzle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Puzzle extends AppCompatActivity {
//get the info
EditText input01 = ( EditText ) findViewById ( R.id.input1 );
EditText input02 = ( EditText ) findViewById ( R.id.input2 );
EditText input03 = ( EditText ) findViewById ( R.id.input3 );
EditText input04 = ( EditText ) findViewById ( R.id.input4 );
EditText input05 = ( EditText ) findViewById ( R.id.input5 );
EditText input06 = ( EditText ) findViewById ( R.id.input6 );
EditText input07 = ( EditText ) findViewById ( R.id.input7 );
EditText input08 = ( EditText ) findViewById ( R.id.input8 );
EditText input09 = ( EditText ) findViewById ( R.id.input9 );
//Button check = ( Button ) findViewById(R.id.check);
Button reset = ( Button ) findViewById(R.id.Reset);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_puzzle);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
reset.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick ( View view ) {
input01.setText ( "" );
input02.setText ( "" );
input03.setText ( "" );
input04.setText ( "" );
input05.setText ( "" );
input06.setText ( "" );
input07.setText ( "" );
input08.setText ( "" );
input09.setText ( "" );
}
}
);
check.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
//process data
int base01 = Integer.valueOf ( input01.getText().toString() );
int base02 = Integer.valueOf ( input02.getText().toString() );
int base03 = Integer.valueOf ( input03.getText().toString() );
int base04 = Integer.valueOf ( input04.getText().toString() );
int base05 = Integer.valueOf ( input05.getText().toString() );
int base06 = Integer.valueOf ( input06.getText().toString() );
int base07 = Integer.valueOf ( input07.getText().toString() );
int base08 = Integer.valueOf ( input08.getText().toString() );
int base09 = Integer.valueOf ( input09.getText().toString() );
base01 = 4;
if ( base01 == result01 ) {
input01.setTextColor(Color.GREEN);
//input02.setTextColor(Color.RED);
}
input01.setTextColor(Color.GREEN);
}
}
);
}
}
And then how do I use the base functions in an if statement without crashing the app, the current if statement I have is crashing the app.
Thanks in advance for any help.
Comments