Search code examples
javaandroideclipsetypesresolve

Eclipse (Android): Cannot be resolved to a type/variable etc


Hey guys after updating Eclipse (Help -> Check for Updates) and Android-SDK-Manager I always get the "…cannot be resolved to a type" or "…cannot be resolved to a variable" message. I get this Error-Message at every single project I already had created as well as on new ones.

I have already tried those things but none of them worked out for me:

  1. Project -> Clean...
  2. Right click at the project -> Properties -> Java Build Path -> Libraries -> Add Library... -> JRE System Library my apps dont run after update eclipse & adt
  3. Window -> Preferences -> Java -> Compiler -> Building -> [x] Rebuild class files modified by others

All those three steps didn't solve those error messages...maybe someone else has an idea what to do? Reinstall Eclipse should be the last option…it totally toke me forever to connect Eclipse with GitHub :(

Example Code:

package com.example.test;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

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

    @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);
    }
}

Error messages:

ActionBarActivity cannot be resolved to a type  MainActivity.java   /TestProject/src/com/example/test   line 7  Java Problem
ActionBarActivity cannot be resolved to a type  MainActivity.java   /TestProject/src/com/example/test   line 11 Java Problem
ActionBarActivity cannot be resolved to a type  MainActivity.java   /TestProject/src/com/example/test   line 31 Java Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.   styles.xml  /TestProject/res/values-v14 line 8  Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml  /TestProject/res/values line 7  Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml  /TestProject/res/values-v11 line 7  Android AAPT Problem
R cannot be resolved to a variable  MainActivity.java   /TestProject/src/com/example/test   line 12 Java Problem
R cannot be resolved to a variable  MainActivity.java   /TestProject/src/com/example/test   line 18 Java Problem
R cannot be resolved to a variable  MainActivity.java   /TestProject/src/com/example/test   line 28 Java Problem
The method getMenuInflater() is undefined for the type MainActivity MainActivity.java   /TestProject/src/com/example/test   line 18 Java Problem
The method onCreate(Bundle) of type MainActivity must override or implement a supertype method  MainActivity.java   /TestProject/src/com/example/test   line 10 Java Problem
The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method MainActivity.java   /TestProject/src/com/example/test   line 16 Java Problem
The method onOptionsItemSelected(MenuItem) of type MainActivity must override or implement a supertype method   MainActivity.java   /TestProject/src/com/example/test   line 23 Java Problem

Solution

  • @ridvanzoro Deleting the appcompat_v7 folder fixed the problem for new projects. I now can try to remove all of my old projects and import them. Thanks :)
    

    You do not need to delete appcompat_v7, there are good xml files , animations inside this folder, you may want use them. To change or remove appcompat_v7 folder from your project,

    Right click at project->Build Path->Configure Build Path->Lİbraries Tab->Android Dependencies