简体   繁体   中英

Multiple Cannot Be Resolved Errors

I'm working in eclipse and I've ran into the same bug that many others have, yet things still don't seem to be working. I'm receiving multiple layout cannot be resolved answers for my drawable and id sources. I tried to order each of my lines with Cntrl shift O and nothing seems to be working.

I'm looking at my activity_mainxml file and I don't see any errors, but based on what I've read on here, that's likely the source of the problem.

Any idea what I could be missing? Any advice would be greatly appreciated.

package com.example.alltruths;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {

    private static final String R = null;
    private AllTruths mAllTruths = new AllTruths();
    private TextView mAnswerLabel;  
    private ImageView mAllTruthsImage;
    private SensorManager mSensorManage;
    private Sensor mAccelerometer;
    private ShakeDetector mShakeDetector;

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


        //Assigning Views from layout
       mAnswerLabel = (TextView) findViewById(R.id.textView1);      
       mAllTruthsImage = (ImageView) findViewById(R.id.imageView1);


    } 

First straightforward error seems to be that you have declared the String R here :

private static final String R = null;

Remove this line and the press Ctrl + Shift + O to import correct R.java . R.java is generated itself and the code references that for accessing your layouts and other res elements.

  1. Remove that String R , you don't need it.
  2. Add the import com.example.alltruths.R; line somewhere between your imports.
mAllTruthsImage.setImageResource(R.Drawable.ball_animation);

If that's copied and pasted, the problem is capitalization. It's R.drawable not R.Drawable .

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