Error: “The following classes could not be found:

2019-08-12 03:52发布

问题:

An app has been using android.support.v7.widget.GridLayout for a while without any problem. I upgraded Android SDK Tools to 22.0.1 this morning. Now, it seems that the app cannot see the library anymore. The Java code has the following error:

The import android.support.v7.widget cannot be resolved

I tried to add a GridLayout to a dummy layout file by dropping GridLayou to it thinking this would help configure the project properly for using GridLayout. However, this generates the following error:

The following classes could not be found:
- android.support.v7.widget.GridLayout

I have restarted Eclipse multiple times and cleaned all projects. Gridlayout_v7.jar is under Android Dependencies and the path is correct.

What should I do to repair the configuration of the project so that android.support.v7.widget.GridLayout can be used?

Computer OS: Windows 8 Pro

CPU: Intel i5

Eclipse (Version: Juno Service Release 2): Build id: 20121004-1855

回答1:

Apparently, you do not have the Android library project containing GridLayout referenced from your project, perhaps because the old reference is now broken.



回答2:

Edit you project's (and library project's too) .classpath file like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>


回答3:

It probably updated your default support v4 lib and now the on in your projetc/lib folder is probably a different version from the one inside v7.

Delete the support v4 jar file in your project/lib folder.

You can have it there and work with the support v7 lib, but v7 already has a v4 lib and they must have the same version to work.

Remove the v4 jar file in your lib folder, then add the v7.



回答4:

Important Change

It has been removed as of API 25.0.0:

You should replace android.support.v7.widget.Space with android.support.v4.widget.Space


See here

android.support.v7.widget.Space has been removed. Usages should be replaced with android.support.v4.widget.Space.