【问题标题】:Error with android.Randroid.R 出错
【发布时间】:2014-12-07 20:21:02
【问题描述】:

您好,我正在开发一个 android 应用程序,没有什么特别适合大学的小东西。在我使用 R 的地方,我在最后一位收到错误。示例 R.id.mediAware 任何帮助将不胜感激。

如果有帮助,这是我的代码:

package com.example.medicalapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.medicalapp.R;

public class MainActivity extends Activity {

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

        ImageView img1 = (ImageView) findViewById(R.id.mediAware);
        ImageView splash_image2 = (ImageView) findViewById(R.id.mediAware2);


        Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fadein);
        Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fadein2);


        fade2.setAnimationListener(new AnimationListener() {
            public void onAnimationEnd (Animation animation) {

                Intent intent = new Intent(new Intent(MainActivity.this, MenuActivity.class));
                startActivity(intent);
            }
            public void onAnimationStart(Animation animation){
            }
            public void onAnimationRepeat(Animation animation){
            }
        });
        splash_image.startAnimation(fade1);
        splash_image2.startAnimation(fade2);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

【问题讨论】:

  • 尝试做一个“干净的构建”然后重建。引用 R 文件时出了点问题
  • 我进行了清理和重建,现在所有活动都包含 R 错误
  • 大多数情况下,您遇到此类错误是因为您的 XML 布局中的其他地方存在错误,请检查您的布局和清单是否存在任何编码错误。
  • 清单文件中没有任何内容。如果我非常简单地创建一个新项目,默认情况下第一个是完美的,如果我添加第二个活动并且不立即编辑任何内容,我会收到与 R 相关的任何错误,而无需在第二个活动中操作任何代码

标签: java android eclipse error-handling syntax-error


【解决方案1】:

我发现了我的问题。我错过了 R.java 文件。要添加文件,我只是在 src 中创建了一个名为 gen 的文件夹,然后清理了项目,这创建了 R.java 文件并删除了我的错误,感谢所提供的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    相关资源
    最近更新 更多