Error R.id.togglebutton1 or more

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 this shows me, for example: "menuoptions cannot be allowed or not a field." 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 clear the project .. delete the class R and all that! What can I do to fix this error? Thanx for helpers ..

+4
source share
1 answer

You get this error because you import android.R , you need to delete this import.

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

When you press control + shift + O to organize imports in eclipse, it sometimes adds imports for android.R

Here is a similar question

+5
source

Source: https://habr.com/ru/post/1445866/


All Articles