gpt4 book ai didi

java - 链接文件资源文件失败

转载 作者:行者123 更新时间:2023-12-02 09:47:30 24 4
gpt4 key购买 nike

您好,我尝试在手机上运行该应用程序(通过 USB)只是为了确保它能正常工作,但出现了此错误。

当我更深入地查看错误时,它提到了有关 XML 文件底部的 centerHorizo​​ntal 的内容。

尝试了一些解决方案,但没有成功。任何帮助都会很棒。非常感谢!

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:paddingBottom="0dp"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
tools:context=".MainActivity">

<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/buttons"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/include"/>
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/hands"
android:layout_centerHoriztonal="true"
android:layout_alignParentTop="true"/>

package com.example.rockpaper;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
Button b_rock, b_paper, b_scissors;
ImageView iv_cpu, iv_me;
String myChoice, cpuChoice, result;
Random r;

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

iv_cpu = (ImageView) findViewById(R.id.iv_cpu);
iv_me = (ImageView) findViewById(R.id.iv_me);

b_rock = (Button) findViewById(R.id.b_rock);
b_paper = (Button) findViewById(R.id.b_paper);
b_scissors = (Button) findViewById(R.id.b_scissors);

r = new Random();

b_rock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myChoice = "rock";
iv_cpu.setImageResource(R.drawable.rock);
calculate();

}
});
b_paper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myChoice = "paper";
iv_cpu.setImageResource(R.drawable.paper);
calculate();

}
});
b_scissors.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myChoice = "scissors";
iv_cpu.setImageResource(R.drawable.scissors);
calculate();


}
});
}

public void calculate() {
int cpu = r.nextInt(3);
if (cpu == 0) {
cpuChoice = "rock";
iv_cpu.setImageResource(R.drawable.rock);
} else if (cpu == 1) {
cpuChoice = "paper";
iv_cpu.setImageResource(R.drawable.paper);

} else if (cpu == 2) {
cpuChoice = "scissors";
iv_cpu.setImageResource(R.drawable.scissors);
}

if(myChoice.equals("rock") && cpuChoice.equals("paper")){
result = "you lose";
} else
if(myChoice.equals("rock") && cpuChoice.equals("scissors")){
result = "you win";
} else
if(myChoice.equals("rock") && cpuChoice.equals("rock")){
result = "draw";
} else
if(myChoice.equals("paper") && cpuChoice.equals("paper")){
result = "draw";
} else
if(myChoice.equals("paper") && cpuChoice.equals("scissors")){
result = "you lose";
} else
if(myChoice.equals("paper") && cpuChoice.equals("rock")){
result = "you win";
} else
if(myChoice.equals("scissors") && cpuChoice.equals("paper")){
result = "you win";
} else
if(myChoice.equals("scissors") && cpuChoice.equals("scissors")){
result = "draw";
} else
if(myChoice.equals("scissors") && cpuChoice.equals("rock")){
result = "you lose";
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
}
}

更详细的错误消息

最佳答案

你的根布局是ConstraintLayout但是这些

android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"

属性属于RelativeLayout

解决方案

要么将根布局更改为RelativeLayout,要么在include标签内给出ConstraintLayout的相应定位元素

喜欢

app:layout_constraintLeft_toRightOf = "id or parent" 
app:layout_constraintRight_toLeftOf = "id or parent"
app:layout_constraintTop_toTopOf = "id or parent"
app:layout_constraintBottom_toBottomOf = "id or parent"

关于java - 链接文件资源文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56543151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com