gpt4 book ai didi

java - Android Studio 在我的代码中没有显示任何错误,但 gradle 却显示了。尝试什么

转载 作者:行者123 更新时间:2023-12-01 11:37:22 25 4
gpt4 key购买 nike

使用 Android Studio。我逐行检查了我的项目代码,不再有红色突出显示或波浪形下划线(在 .xml、.java 文件中)。事实上,所有项目文件都没有红色下划线。我尝试关闭并重新打开 android studio。没有运气。当我清理项目时,我收到错误消息:无法完成 gradle 执行 - 原因:读取超时。其次,当我运行项目时,我收到运行应用程序时出错:Gradle 项目同步失败。请修复您的项目并重试。将不胜感激任何帮助。代码如下。

Java 文件:

package com.teamtreehouse.funfacts;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class FunFactsActivity extends Activity {

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

//Declare our view variables and assign them the views from the layout file
final TextView factlabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
// The button was clicked so update the fact label with a new fact
String fact = "Ostriches can run faster than horses";
factlabel.setText(fact);
}
};
showFactButton.setOnClickListener(listener);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.fun_facts, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

XML 文件:

<TextView
android:text="Did you know!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#80ffffff" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ants stretch when they wake up in the morning"
android:id="@+id/factTextView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="24sp"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show another fun fact"
android:id="@+id/showFactButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/white" />

</RelativeLayout>

最佳答案

检查 gradle 控制台以了解 gradle 同步失败的原因。它位于右下角。

你是从eclipse导入项目的吗?

检查您的 SDK 管理器,了解您是否安装了与您正在使用的版本相同的构建工具和 Android 支持。

关于java - Android Studio 在我的代码中没有显示任何错误,但 gradle 却显示了。尝试什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29832608/

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