简体   繁体   中英

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

Cmd-shift-O on OSX

Ctrl+Shift+O on Windows / Linux

Rawkode Still Getting 2 Error : " Unknown entity 'uri" and "Unknown member 'main of 'com.aamir.cool.R.id"

Please ensure that main.xml actually exists in your layout folder.

After importing the 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. 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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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