简体   繁体   中英

Migrating to Android Studio: Class resolved in editor, but cannot be found while building

Story : I am completely new to Android development, and this is an eclipse project I have to start working with, but I would prefer to use AS. Consequently I used the import mechanism. Note I had to switch to targetSdkVersion 23 , or AS would give me errors.

Problem It seems the automatically generated build configuration does something out of order.

When trying to build, the gradle task :app:compileDebugJavaWithJavac fails in MainActivity.java:68 :

Error:(68, 59) error: cannot find symbol class ToDoItem

The Project contains a class ToDoItem which is used here:

public class MainActivity extends Activity {

    public static class ListViewAdapter extends ArrayAdapter<ToDoItem>
            implements OnCreateContextMenuListener {
...

beginning of app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "androidlab.exercise4_1"
        minSdkVersion 17
        targetSdkVersion 23
    }

In the Editor ToDoItem resolves just fine. I have no idea how to even start dealing with this problem.

In order to have a nice architecture and that can be easily debugged, I would try to do the following:

  1. Move the adapter class out of the activity and give a callback to the adapter.

  2. Try to check if the application class is referenced properly in the manifest and also in the gradle file.

  3. Check if you don't have some resource problems.

  4. Clear the entire project and build it again.

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