【问题标题】:Solve Compile error in Android Studio?解决 Android Studio 中的编译错误?
【发布时间】:2023-10-29 19:44:01
【问题描述】:

我不断收到诸如 error:atrribute paddingleft not found 和 failed linking file resources 错误之类的错误,还有其他一些人知道我在 main.java 类中的问题的解决方案吗?我将其设置为 setContentView(R.layout.activity_main);

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
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"
    android:orientation="vertical"
    tools:context="com.example.issacrodriguez.robber.main">

    <TextView
        android:id="@+id/scoreLabel"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:paddingLeft="50dp"
        android:paddingleft="10dp"
        android:text="Score : 300"
        android:textSize="18sp" />

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/StartLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tap To Start!"
            android:textSize="30sp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="130dp" />

       <ImageView
            android:id="@+id/robber"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/robberr"
            android:layout_gravity="center_vertical"/>

       <ImageView
        android:id="@+id/moneybag"
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:src="@drawable/moneybag" />

        <ImageView
            android:id="@+id/cop"
            android:layout_width="60dp"
            android:layout_height="24dp"
            android:src="@drawable/cop"/>

    </FrameLayout>




</LinearLayout>

【问题讨论】:

  • Android Studio**
  • @+id/scoreLabel ID 中的错误,1. 错误的属性名称 (paddingleft) 和 2. 写了两次错误 (paddingLeft)。

标签: java android android-studio


【解决方案1】:

在这种情况下你做错了-:

<TextView
     android:id="@+id/scoreLabel"
     android:layout_width="match_parent"
     android:layout_height="50dp"
     android:gravity="center_vertical"
     android:paddingLeft="50dp"
     android:text="Score : 300"
     android:textSize="18sp" />

我们在 android 中只有 android:paddingLeft="50dp" 而不是类似的东西 android:paddingleft="10dp" 删除它会编译然后。

【讨论】: