简体   繁体   English

如何解决这个意图错误?

[英]How to solve this intent Error ?

I Wrote the Following code : 我写了以下代码:

package com.aamir.cool;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

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

        ImageView img = (ImageView)findViewById(R.id.facebook);
        img.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                intent.setData(Uri.parse("http://www.facebook.com/exandrok?ref=tn_tnmn"));
                startActivity(intent);
            }
        });
    }
}

I am getting error "Unknown Entity Intent" , "Unknown type of variable intent" . 我收到错误“未知实体意图”,“变量意图的未知类型”。 How to Solve these Error ? 如何解决这些错误?

Add the following lines to your import statements: 将以下行添加到您的导入语句:

import android.content.Intent;
import android.net.Uri;

Add the correct import statements 添加正确的导入语句

import android.content.Intent
import android.net.Uri;

If you're using Eclipse, you can add/organise/optimise your imports with the following shortcut 如果您使用的是Eclipse,则可以使用以下快捷方式添加/组织/优化导入

Cmd-shift-O on OSX OSX上的Cmd-shift-O

Ctrl+Shift+O on Windows / Linux 在Windows / Linux上为Ctrl+Shift+O

Rawkode Still Getting 2 Error : " Unknown entity 'uri" and "Unknown member 'main of 'com.aamir.cool.R.id" Rawkode仍在2错误:“'com.aamir.cool.R.id的未知实体'uri'和'未知成员'main”

Please ensure that main.xml actually exists in your layout folder. 请确保main.xml实际上存在于您的layout文件夹中。

After importing the android.content.Intent; 导入android.content.Intent之后; first check your xml files and be sure you dont have any layout problems and delete your R.java file and let it generate that again. 首先检查您的xml文件,并确保您没有任何布局问题,然后删除R.java文件并让它再次生成。 after doing that right click to your project Android Projects -> Fix Project Properties then select "Project" and click "Clear" then try to run the code again. 完成该操作后,右键单击您的项目Android项目->修复项目属性,然后选择“项目”,然后单击“清除”,然后尝试再次运行代码。 if still not working ctrl+a ctrl+x and ssave the file be sure you have no errors and ctrl+v again and try to run again. 如果仍然无法正常使用ctrl + a ctrl + x并保存文件,请确保没有错误,再次输入ctrl + v并尝试再次运行。

尝试验证主页中的AndriodManifest.xml,该文件会生成包,如gen / com文件夹所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM