4
package com.example.hello.word;

import android.R;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;

public class OptionsMenu extends Activity{

    MediaPlayer ourSong;
    Button btn1;
    Intent openStartingPoint;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menuoptions);

        final ToggleButton onTog = (ToggleButton) findViewById(R.id.toggleButton1);
        onTog.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (onTog.isChecked()){
                    ourSong.start();
                }else{
                    ourSong.stop();
                }
            }
        });

I have an error under all the Buttons and its shows me for example: "menuoptions cannot be resolved or is not field".. the same error on togglebutton1

my XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Volume"
        android:textSize="40dp"
        android:textStyle="bold"
        android:layout_marginTop="40dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="121dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="ToggleButton" />

    <Button
        android:id="@+id/button1"
        android:layout_width="178dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="150dp"
        android:text="Back" />

</LinearLayout>

I tried to clean the project.. delete the R class and everything! what I can do to fix that Error? Thanx for helpers..

1 Answers1

5

You are getting that error because your are importing android.R you have to remove this import.

Try removing the line import android.R; from your code, this should fix your problem

When you press control + shift + O to organise your imports in eclipse, it sometimes adds the import for android.R

Here is a similar question

Community
  • 1
  • 1
jcw
  • 5,132
  • 7
  • 45
  • 54