您的位置:首页 > 大数据 > 人工智能

R.layout.main cannot be resolved解决办法

2014-12-31 12:29 337 查看
今天敲的代码

[java] view plaincopy

package com.sharpandroid.activity;

import android.R;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class AlertDialogActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

AlertDialog.Builder builder =

new AlertDialog.Builder(AlertDialogActivity.this);

builder.setTitle("sharpandroid")

.setMessage("你确定要访问Android网站吗?")

.setCancelable(false)

.setPositiveButton("确定",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,int id){

Intent intent =

new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));

startActivity(intent);

}})

.setNegativeButton("取消",

new DialogInterface.OnClickListener(){

public void onClick(DialogInterface dialog,

int id){

dialog.cancel();

}

});

AlertDialog alert = builder.create();

alert.show();

}

});

}

}

出现如下问题:



鼠标放到出代码上面:



分析问题:

1、查看R文件是否被生成,如果没有生成,则勾选build Automatically,然后Clean:





2、如果R文件已生成,则删除去掉代码中:

[java] view plaincopy

import android.R;

重新build问题解决。

备注: 删除"import android.R"之后工程就是从/res文件夹下自动生成的资源文件里去解析了,否则它会从Android的资源类里去找。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: