无法解析符号 R [英] Cannot Resolve symbol R

查看:55
本文介绍了无法解析符号 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Studio 上工作以添加简短的 toast 消息.(我正在制作一个 Android Wear 应用程序)

I was working on Android Studio for adding a short toast message.(I was making an Android Wear Application)

我不知道为什么这段代码在 'symbol R' 上有错误.它说无法解析符号 R."

I couldn't know why this code has error on 'symbol R' . It says "Cannot Resolve Symbol R."

    import android.app.Activity;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.support.wearable.view.WatchViewStub;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.Toast;

    public class MyActivity extends Activity {

        private TextView mTextView;

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

    //getnextpage
    Button getnextpage;
    getnextpage = (Button) findViewById(R.id.getnextpage);
    getnextpage.setOnClickListener(new OnclickListener() {
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Here is 2nd Page", Toast.LENGTH_LONG).show();
        }
    });
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
            mTextView = (TextView) stub.findViewById(R.id.text);
        }
    });
  }
 }

推荐答案

下面提到了一些程序:

1) 尝试 Build -> Clean/Rebuild 项目.

1) Try Build -> Clean/Rebuild project .

2) 手动输入 import .R,如果 import R 丢失.

2) Manually typing import <package name>.R, If in import R is missing.

3) 完成其对应的XML文件的所有资源.

3) complete all resources of its corresponding XML file .

我希望其中任何一个对您有所帮助,因为没有特定的方法可以解决此问题.

I hope any one of them would be helpful for you as there is no Particular way to resolve this issue.

这篇关于无法解析符号 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆