java - 未找到 Android ID(当它存在时)

标签 java android xml

Android Studio 在主 Activity Java 中因未解析的符号或 id 给出错误。据我所知,java代码中引用的id是存在的。

在另一个使用相同原理的应用程序中,它起作用了,我交叉引用了这两个应用程序,但找不到任何突出的内容。

这是我的java代码:

package com.example.android.quizapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

public class QuizMainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz_main);
}
public void display(int value) {
    TextView quantityTextView = findViewById(R.id.value_text);
    quantityTextView.setText(value);
}
public void slider(View view){
    SeekBar seekBar = (SeekBar)findViewById(R.id.i);
    int Value = seekBar.getProgress();
    EditText text = (EditText)findViewById(R.id.valueText);

    String name = text.getText().toString();
    text.setText(Value);
}
}

这是我的 XML:(ID 在那里)

<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.quizapplication.QuizMainActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Quiz"
    android:textAlignment="center"/>

<TextView
    android:id="@+id/question"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="What is you favorite color?"
    android:textAlignment="center"
    android:paddingTop="20dp"
    android:textSize="20dp"
    android:textStyle="bold"

    android:textColor="#000000"
    android:layout_below="@+id/title"
     />
    <TextView
        android:id="@+id/value_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test"
        android:textAlignment="center"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="300dp"/>
    <SeekBar
        android:id="@+id/i"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="146dp"
        android:onClick="slider"/>


</RelativeLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
     />

最佳答案

尝试添加以下内容:

import com.example.android.quizapplication.R;

关于java - 未找到 Android ID(当它存在时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49514090/

相关文章:

java - 在 gradle 中将 JRE 与 launch4j 应用程序捆绑在一起

Java:如何在 JFileChooser 中读取 "Files of type"

java - 订购具有重复字符串的 ArrayList

android - 如何列出应用程序公开的所有 Activity ?

android - 在 XML 中的自定义 ScrollView 上膨胀类时出错?

python - 将 XML 保存为变量中的 ctypes c_byte 会给出 TypeError : an integer is required

java - 这个线程有什么问题?它只运行一次。 (带有 GPS 位置的线程)

java - file.delete() 不彻底删除遗留的图像空白图像文件

java - DatePicker在datepicker中指明出生日期,然后显示下一个生日的天数以及本次生日?

c++ - 在 Qt 中解析 XML