Android说找不到资源文件

时间:2019-05-10 10:19:07

标签: java android

我只做过xml,还没有移到Java上,但是我无法在模拟器上运行该程序,因为它不断向我抛出相同的错误。我看过其他问题,例如我的问题,却找不到有效的答案。

我尝试清理并重新构建项目

这是我拥有的xml代码

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
    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:background="@drawable/gradient"
    tools:context="MainActivity">

    <ImageView
        android:id="@+id/logoView"
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:layout_marginTop="40dp"
        app:srcCompat="@drawable/download"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/usernameText"
        android:layout_width="250dp"
        android:layout_height="40dp"
        android:background="#11000000"
        android:ems="10"
        android:hint="Username"
        android:inputType="textPersonName"
        android:textSize="16dp"
        android:layout_marginBottom="35dp"
        android:layout_above="@+id/passwordText"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/passwordText"
        android:layout_width="250dp"
        android:layout_height="40dp"
        android:background="#11000000"
        android:ems="10"
        android:hint="@string/password"
        android:inputType="textPassword"
        android:layout_marginBottom="130dp"
        android:layout_alignBottom="@+id/btnLogin"
        android:layout_alignLeft="@+id/usernameText"
        android:layout_alignStart="@+id/usernameText"
        android:autofillHints="" />

    <android.widget.Button
        android:text="@string/login"
        android:layout_width="300dp"
        android:layout_height="50dp"
        android:id="@+id/btnLogin"
        android:layout_marginBottom="31dp"
        android:layout_above="@+id/linkRegister"
        android:layout_centerHorizontal="true">
    </android.widget.Button>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/lblLogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/login"
            android:textColor="#fff"
            android:textSize="18sp" />
    </RelativeLayout>

    <TextView
        android:id="@+id/linkRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/register_here"
        android:layout_above="@+id/linearLayout"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="6dp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:id="@+id/linearLayout">
    </LinearLayout>
</android.widget.RelativeLayout>

这是我目前拥有的Java代码

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

这是我遇到的错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidtask2/com.example.androidtask2.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
        at android.content.res.Resources.getValue(Resources.java:1351)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2774)
        at android.content.res.Resources.getLayout(Resources.java:1165)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.example.androidtask2.MainActivity.onCreate(MainActivity.java:10)
        at android.app.Activity.performCreate(Activity.java:6237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

1 个答案:

答案 0 :(得分:0)

这是一个很常见的错误。尝试清理您的项目并重建它:

从菜单栏中-

构建>清理项目

此后,

构建>重建项目