K
K
Kirill Yaroshevich2016-11-04 01:01:43
Java
Kirill Yaroshevich, 2016-11-04 01:01:43

MainActivity.java how to fix error?

you need the button to be clickable, public void onClick(View view - this marks red):
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, PreferenceScreen.class);
startActivity(intent);
}
an error occurs:
Error:(121, 13) error: illegal start of expression
Error:(121, 20) error: illegal start of expression
Error:(121, 32) error: ';' expected
Error:(121, 33) error: not a statement
Error:(121, 37) error: ';' expected
Error:(121, 39) error: not a statement
Error:(121, 43) error: ';' expected

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Serkov, 2016-11-04
@Hutaab

public class MainActivity extends AppCompatActivity {

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

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(MainActivity.this, PreferenceScreen.class);
                startActivity(intent);
            }
        });
    }
}

S
suda911, 2016-11-24
@suda911

Set the value of the onClick parameter of the button to your method and everything will be ok) Or do as suggested already)8e9973efe0e94956bd66d8f281380501.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question