【问题标题】:Cannot resolve method and LinearLayout无法解析方法和 LinearLayout
【发布时间】:2016-04-13 21:19:42
【问题描述】:

我的代码有问题... 之前,它有效,然后我在布局中添加了一些简单的线条,现在我有很多错误。我正在尝试自己学习如何为我的学校图书馆做一个应用程序,所以我不是专业人士。 感谢您的帮助。

这里的错误是“无法解析 R”

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

    majorOb = (Spinner) findViewById(R.id.spinnerMaj);
    yearOb = (Spinner) findViewById(R.id.spinnerYear);
    semesterOb = (Spinner) findViewById(R.id.spinnerSem);
    classOB = (Spinner) findViewByID(R.id.spinnerClass);
    button1 = (Button) findViewById(R.id.button1);
    tv1 = (TextView) findViewById(R.id.textview1);
    Resources res = getResources();
    array1 = res.getStringArray(R.array.Books);`

这里的错误是:Element LinearLayout没有必需的属性:layout_height和layout_width

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.marcosbiblio.projetofinal.MainActivity">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

【问题讨论】:

  • 对于“无法解析 R”,从构建选项清理并重建项目
  • 确保您正在处理具有以下路径的文件:- "src/main/res/layout/your_file_name.xml"

标签: android-layout main-activity


【解决方案1】:

试试这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.marcosbiblio.projetofinal.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"></LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    相关资源
    最近更新 更多