gpt4 book ai didi

android - 我如何解决 R.layout.main 无法在我的 android 应用程序中解析?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:53:32 24 4
gpt4 key购买 nike

我是一名 Android 应用开发新手。我发现一个问题。那就是 R.layout.main 无法解析。我该如何解决我的问题。我的代码在这里。请解决我的问题。

 package com.android;

import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class HelloActivity extends Activity {
/** Called when the activity is first created. */

Button bt;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt=(Button)findViewById(R.id.ButtonOk);
bt.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
//Toast.makeText(getBaseContext(), "Welcome Android World", 3000).show();
Intent intent = new Intent(HelloActivity.this, DisplayActivity.class);
startActivity(intent);
}
});
}
}




*

and my xml code is here:

*

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:id="@+id/ButtonOk" android:height="50dp" android:width="100dp"></Button>
</LinearLayout>

最佳答案

第 1 步:删除 import android.R;

第 2 步:清理并重建(应该可以)

如果不是

然后关闭项目退出eclipse再打开。按照它应该工作的步骤进行操作。

如果不是

改变你的包裹

来自

import android.R;

import yourpackage.R;

它应该工作

关于android - 我如何解决 R.layout.main 无法在我的 android 应用程序中解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14200259/

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