我刚刚下载并安装了新的Android SDK.我想创建一个简单的应用程序来测试它.

向导创建了以下代码:

package eu.mauriziopz.gps;

import android.app.Activity;
import android.os.Bundle;

public class ggps extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

但是Eclipse给了我一个错误

R无法解决

在线上

setContentView(R.layout.main);

为什么?

PS:我有一个名为res/layout/main.xml的XML文件.

推荐答案

威尔说的是对的

R is an automatically generated class that holds the constants used to identify your >resources. If you don't have an R.java file (it would be gen/eu.mauriziopz.gps/R.java in >Eclipse with the 1.5 SDK) I would recommend closing and reopening your project or going to >Project > Build all (and selecting "Build Automatically" while there as recommended by >Josef). If that doesn't work than try making a new project, if the problem is recreated than >post here again and we'll go into more detail.

但我发现还有另一个问题导致了第一个问题.SDK目录中的工具没有要执行的权限,因此就好像Eclipse不存在,因此它没有构建R.java文件.

因此,修改权限并 Select "自动构建"解决了问题.

Android相关问答推荐

如何将Hilt添加到Android Studio中的Kotlin项目中?

如何使用视图模型触发可变状态?

Jetpack Compose Scaffold—content不在TopAppBar下面开始'

Android Compose Lazy柱形实时UI更改

如何禁用Android 34+版的TileService,但保留以前的版本?

如何使用Jetpack Compose实现此底表?

在Android 14/SDK 34中使用RegisterReceiver的正确方式是什么?

无法加载类';com.android.build.api.extension.AndroidComponentsExtension';

从惰性列中删除项目时Jetpack Compose崩溃

在内部创建匿名对象的繁忙循环调用函数会产生开销吗?

如何在使用带有底部导航组件的片段管理器时更改片段工具栏的标签

如何在Android中将以前的数据保存在复选框中?

Visual Studio 2022,毛伊岛,Android Emulator:无法更改内存量

当 EditText 用于在 android studio 中将字符串发送到 firebase 时,仅允许安全调用错误

appcompat 依赖从何而来?

如何知道我的应用程序的新版本是否显示广告?

如何以编程方式通过 whatsapp android 共享图像和文本

如何在 React Native 中调试网络响应

AttributionSource 需要 android.permission.BLUETOOTH_SCAN 权限的问题

如何在jetpack compose中创建自定义rememberState?