Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法解析符号R?_Android - Fatal编程技术网

Android 无法解析符号R?

Android 无法解析符号R?,android,Android,我是android新手,看到其他人也有同样的问题,但解决方案不起作用 我多次尝试在更改后清理、同步和构建项目,但每次都是说它无法解决R 添加:导入nl.test123.R无法工作,因为出现了下一个错误popsup:错误:未找到属性“nl.test123.音板:布局\u背景”。 这也没用 import android.R 这是代码:“MainActivity.java” 有人能看出我做错了什么或忘记了做什么吗 请参阅下面的xml:“activity_main.xml” 使用yourpackag

我是android新手,看到其他人也有同样的问题,但解决方案不起作用

我多次尝试在更改后清理、同步和构建项目,但每次都是说它无法解决R

添加:
导入nl.test123.R
无法工作,因为出现了下一个错误popsup:
错误:未找到属性“nl.test123.音板:布局\u背景”。

这也没用

import android.R
这是代码:“MainActivity.java”

有人能看出我做错了什么或忘记了做什么吗

请参阅下面的xml:“activity_main.xml”



使用
yourpackagename.R

在您的情况下,它将是
nl.test123.testsoundboard.R


我认为你的布局有错误
BottomNavigationView
没有
app:layout\u background
属性。删除它并重新生成。

删除了这一行:
app:layout_background=“@color/colorPrimary”
但仍然收到错误。@Fcmarv请在删除该行后输入收到的新错误消息。仍然是相同的“无法解析符号R”我删除了按钮上的行安卓:onClick=“Sound1”,错误也消失了?就像一句话,我在其他问题中尝试了这些解决方案,但都不起作用。解决方案应该是
android:onClick=“Sound1”
package nl.test123.testsoundboard;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
//import nl.test123.R;

public class MainActivity extends AppCompatActivity {
    MediaPlayer mysound1;
    MediaPlayer mysound2;
    MediaPlayer mysound3;

    private TextView mTextMessage;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_top:
//                    mTextMessage.setText(R.string.title_top);
                    return true;
                case R.id.navigation_latest:
//                    mTextMessage.setText(R.string.title_latest);
                    return true;
                case R.id.navigation_favorite:
//                    mTextMessage.setText(R.string.title_favorite);
                    return true;
            }
            return false;
        }
    };

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

        mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);


        mysound1 = MediaPlayer.create(this, R.raw.bird);
        mysound2 = MediaPlayer.create(this, R.raw.bomb);
        mysound3 = MediaPlayer.create(this, R.raw.dog);
    }

    public void sound1(View view){
        mysound1.start();
    }
    public void sound2(View view){
        mysound2.start();
    }
    public void sound3(View view){
        mysound3.start();
    }
}
 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="nl.marvinboontjes.cucumbersoundboard.MainActivity">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="92dp"
        android:layout_marginTop="128dp"
        android:text="@string/title_home"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_light"
        android:onClick="Sound1"
        android:text="Bird"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp"
        tools:ignore="MissingConstraints" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="sound2"
        android:text="Bomb"
        tools:layout_editor_absoluteX="147dp"
        tools:layout_editor_absoluteY="16dp"
        tools:ignore="MissingConstraints"  />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onclick="sound3"
        android:text="Dog"
        tools:layout_editor_absoluteX="269dp"
        tools:layout_editor_absoluteY="16dp"
        tools:ignore="MissingConstraints" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:layout_background="@color/colorPrimary"
        app:itemIconTint="@drawable/nav_item_color_state"
        app:itemTextColor="@drawable/nav_item_color_state"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>