Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

void is an invalid type for this variable

Tags:

java

android

void

I am getting this error:

void is an invalid type for the variable onRadioButtonClicked

But the developer site says that void is a must! So where is the problem? The coding of the xml's is correc.. The problem must lie somewhere here:

package com.example.kernel.version;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;

public class MainPage extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent=getIntent();
        setContentView(R.layout.activity_main_page);       

        public void onRadioButtonClicked(View view) {
            // Is the button now checked?
            boolean checked = ((RadioButton) view).isChecked();

            // Check which radio button was clicked
            switch(view.getId()) {
                case R.id.radio_pirates:
                    if (checked)
                        // Pirates are the best
                    break;
                case R.id.radio_ninjas:
                    if (checked)
                        // Ninjas rule
                    break;
            }

        }
like image 518
Naman Arora Avatar asked Jan 14 '23 14:01

Naman Arora


1 Answers

Your onRadioButtonClicked is contained within your onCreate method—make them separate methods. Add a closing brace } after:

setContentView(R.layout.activity_main_page); 
like image 144
Reimeus Avatar answered Jan 21 '23 19:01

Reimeus