Android Studio - 无法解析方法和符号

标签 android android-studio

我正在开发一个简单的应用程序,但今天,就在我点击“清理项目”之后,由于可绘制资源的一些错误,我的应用程序无法再运行。

我有这个简单的 Activity :

package com.elisafedeli.consiglipergenitori.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.view.View.OnClickListener;

public class About extends Activity implements OnClickListener{

    //Variabili
    ImageButton fb = null;
    ImageButton twitter = null;
    ImageButton linkedin = null;
    ImageButton sito = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Mostro la grafica
        setContentView(android.R.layout.about);

        //Recupero tutti i pulsanti
        fb = (ImageButton)findViewById(android.R.id.logoFB);
        twitter = (ImageButton)findViewById(android.R.id.logoTwitter);
        linkedin = (ImageButton)findViewById(android.R.id.logoLindedIn);
        sito = (ImageButton)findViewById(android.R.id.logoSito);

        //Aggiungo il click listener
        fb.setOnClickListener(this);
        twitter.setOnClickListener(this);
        linkedin.setOnClickListener(this);
        sito.setOnClickListener(this);

        //Ad ogni listener aggiungo un valore così posso eseguire azioni diverse
        fb.setTag(0);
        twitter.setTag(1);
        linkedin.setTag(2);
        sito.setTag(3);
    }

    @Override
    public void onClick(View v) {

        //Recupero il valore del bottone
        Integer valore_bottone = (Integer) v.getTag();
        Intent ritorno;

        switch (valore_bottone){
            case 0:{
                ritorno = getOpenFacebookIntent(getApplicationContext());
                startActivity(ritorno);
                break;
            }
            case 1:{
                break;
            }
            case 2:{
                break;
            }
            case 3:{
                break;
            }
        }

    }

    //Se l'app di FB è installata apro la pagina
    //Altrimenti il browser
    public static Intent getOpenFacebookIntent(Context context) {

        try {
            context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
            return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/510231222394702"));
        } catch (Exception e) {
            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/pages/Bambini-al-nido/510231222394702"));
        }
    }
}

但是我无法编译它,我有以下错误:

setContentView(android.R.layout.about);

fb = (ImageButton)findViewById(android.R.id.logoFB);
        twitter = (ImageButton)findViewById(android.R.id.logoTwitter);
        linkedin = (ImageButton)findViewById(android.R.id.logoLindedIn);
        sito = (ImageButton)findViewById(android.R.id.logoSito);

和 AndroidStudio 报告:

Gradle invocation completed successfully with 6 error(s) in 10 sec

enter image description here

但是,正如您所看到的,资源位于可绘制文件夹中(在我清理之前它已经工作):

enter image description here

并在 xml 布局中正确设置:

enter image description here

我该如何解决?

最佳答案

尝试在所有地方用 R 替换 android.R

关于Android Studio - 无法解析方法和符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22281413/

相关文章:

android - 新的 PayPal 沙盒测试用户帐户

android - 如何设置/发送地理定位参数纬度/经度到 Android-x86 模拟器

java - GPS应用程序消耗多少功率?

android - RadioGroup onCheckedChangeListener 出错

android-studio - 尝试从 Android Studio 启动我的应用时出现 NoSuchMethodException

android - 更新后模拟器出现问题

Android Studio - Proguard 'keep' 规则被忽略?

安卓+gradle : injecting a task into build

javascript - 从 Android 浏览器打开 Instagram

android - 从 XML 资源生成 ListViewItems