2016-06-21 8 views
5

Ich versuche mit Kotlin zu beginnen, indem ich einige Java-Klassen meines Projekts in Kotlin umwandle und ein gemischtes Java/Kotlin-Projekt erstelle. Um die Umgebung zu konfigurieren, habe ich Folgendes getan:Wie zu lösen: "Fehler: kann Symbolklasse nicht finden ..." nach dem Konvertieren der Java-Klasse in Kotlin?

  1. Heruntergeladen die neueste Version von Kotlin Plugin (1.0.2);
  2. Auf der obersten Ebene gravel.plugin habe ich hinzugefügt: classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.0.2" in den Abhängigkeiten Abschnitt;
  3. In meinem Modul Gradle Plugin habe ich hinzugefügt: compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.2" in den Abhängigkeiten Abschnitt;
  4. Ich habe die POJO-Klasse ausgewählt, die ich in Kotlin konvertieren wollte, ausgewählt aus dem Menü Code -> Java-Datei in Kotlin-Datei konvertieren;
  5. Danach wurden alle Java-Klassen angezeigt, die die konvertierte Klasse importierten: . Im Folgenden ist die ursprüngliche Klasse, die konvertierte Klasse und das Protokoll:

Original-Java-Klasse:

package br.com.gogame.model; 

import com.google.gson.Gson; 
import com.orm.SugarRecord; 
import com.orm.dsl.Ignore; 

import java.io.Serializable; 
import java.util.List; 

import br.com.gogame.model.enums.ChatType; 

/** 
* Created by edgar on 11-Apr-16. 
*/ 
public class Chat extends SugarRecord implements Serializable { 

    private String title; 
    private String thumbnail; 
    private ChatType chat_type; 
    private long chat_id; 
    private int num_of_members; 
    private long user_id; 
    @Ignore 
    private List<Long> users; 

    public Chat() { 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getThumbnail() { 
     return thumbnail; 
    } 

    public void setThumbnail(String thumbnail) { 
     this.thumbnail = thumbnail; 
    } 

    public ChatType getChat_type() { 
     return chat_type; 
    } 

    public void setChat_type(ChatType chat_type) { 
     this.chat_type = chat_type; 
    } 

    public long getChat_id() { 
     return chat_id; 
    } 

    public void setChat_id(long chat_id) { 
     this.chat_id = chat_id; 
    } 

    public int getNum_of_members() { 
     return num_of_members; 
    } 

    public void setNum_of_members(int num_of_members) { 
     this.num_of_members = num_of_members; 
    } 

    public long getUser_id() { 
     return user_id; 
    } 

    public void setUser_id(long user_id) { 
     this.user_id = user_id; 
    } 

    public List<Long> getUsers() { 
     return users; 
    } 

    public void setUsers(List<Long> users) { 
     this.users = users; 
    } 

    @Override 
    public String toString() { 
     Gson gson = new Gson(); 
     return gson.toJson(this, Chat.class); 
    } 
} 

Converted Kotlin Klasse

package br.com.gogame.model 

import com.orm.SugarRecord 
import com.orm.dsl.Ignore 

import java.io.Serializable 

import br.com.gogame.model.enums.ChatType 

/** 
* Created by edgar on 11-Apr-16. 
*/ 
class Chat : SugarRecord(), Serializable { 
    var title: String? = null 
    var thumbnail: String? = null 
    var chat_type: ChatType? = null 
    var chat_id: Long = 0 
    var num_of_members: Int = 0 
    var user_id: Long = 0 
    @Ignore 
    var users: List<Long>? = null 
} 

Fehlerprotokoll:

C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\commons\infra\App.java 
    Error:(8, 42) error: cannot find symbol class DaggerMainComponent 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\view\fragments\FragmentChats.java 
    Error:(23, 27) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\communication\post_office\GCMOffice.java 
    Error:(25, 27) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\controller\util\JSONParser.java 
    Error:(22, 27) error: cannot find symbol class Chat 
    Error:(98, 17) error: cannot find symbol class Chat 
    Error:(111, 60) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\controller\ChatController.java 
    Error:(23, 27) error: cannot find symbol class Chat 
    Error:(41, 12) error: cannot find symbol class Chat 
    Error:(46, 12) error: cannot find symbol class Chat 
    Error:(62, 32) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\commons\util\FakeDataProvider.java 
    Error:(7, 27) error: cannot find symbol class Badge 
    Error:(8, 27) error: cannot find symbol class Chat 
    Error:(21, 24) error: cannot find symbol class Badge 
    Error:(94, 24) error: cannot find symbol class Chat 
    Error:(106, 20) error: cannot find symbol class Chat 
    Error:(118, 20) error: cannot find symbol class Chat 
    Error:(130, 20) error: cannot find symbol class Chat 
    Error:(142, 20) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\controller\util\NotificationFactory.java 
    Error:(19, 27) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\model\dao\ChatDAO.java 
    Error:(13, 27) error: cannot find symbol class Chat 
    Error:(24, 29) error: cannot find symbol class Chat 
    Error:(46, 19) error: cannot find symbol class Chat 
    Error:(60, 19) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\model\dao\ChatUserDAO.java 
    Error:(7, 27) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\model\dao\Datamanager.java 
    Error:(9, 27) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\model\dao\LocalUserDAO.java 
    Error:(8, 27) error: cannot find symbol class Chat 
    Error:(145, 24) error: cannot find symbol class Chat 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\view\adapters\BadgesAdapter.java 
    Error:(15, 27) error: cannot find symbol class Badge 
    Error:(21, 52) error: cannot find symbol class Badge 
    Error:(25, 60) error: cannot find symbol class Badge 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\controller\FriendshipController.java 
    Error:(21, 27) error: cannot find symbol class Chat 
    Error:(195, 79) error: cannot find symbol class Chat 
    Error:(33, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\controller\MessageController.java 
    Error:(23, 27) error: cannot find symbol class Chat 
    Error:(91, 50) error: cannot find symbol class Chat 
    Error:(117, 61) error: cannot find symbol class Chat 
    Error:(128, 65) error: cannot find symbol class Chat 
    Error:(216, 46) error: cannot find symbol class Chat 
    Error:(34, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\view\activities\ActivityCanvas.java 
    Error:(38, 27) error: cannot find symbol class Chat 
    Error:(64, 13) error: cannot find symbol class Chat 
    Error:(53, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\view\activities\ActivityFriends.java 
    Error:(22, 27) error: cannot find symbol class Chat 
    Error:(196, 13) error: cannot find symbol class Chat 
    Error:(39, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\view\adapters\ChatAdapter.java 
    Error:(26, 27) error: cannot find symbol class Chat 
    Error:(35, 50) error: cannot find symbol class Chat 
    Error:(43, 58) error: cannot find symbol class Chat 
    Error:(35, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. 
    C:\SIBEN\Edgar\workspace\GoGame\current\app\src\main\java\br\com\gogame\commons\infra\dagger\MainComponent.java 
    Error:(42, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. 
    Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
    > Compilation failed; see the compiler error output for details. 
    Information:BUILD FAILED 
    Information:Total time: 7.406 secs 
    Information:51 errors 
    Information:4 warnings 
    Information:See complete output in console 
+2

Es sieht so aus, als ob Ihr Kotlin-Code nicht während des Build-Prozesses kompiliert wird. Haben Sie die erforderlichen Plugins installiert, wie das [tutorial] (https://kotlinlang.org/docs/reference/using-gradle.html#targeting-android) suggeriert? Sehen Sie sich auch dieses [Beispiel] an (https://github.com/JetBrains/kotlin-examples/tree/master/gradle/android-mixed-java-kotlin-project) – Ilya

+0

Das war es! Ich habe '' 'Apply Plugin hinzugefügt: 'Kotlin-android'''' und jetzt .kt-Datei wird kompiliert und erkannt. Vielen Dank. –

+1

@EdgarDaSilvaFernandes Sie sollten eine Antwort zu dieser Frage hinzufügen und erklären, was Sie getan haben, um es zu beheben, und es als die akzeptierte Antwort markieren :) – Rocoty

Antwort

7

Wie vom Benutzer @Ilya gezeigt, bestand das Problem darin, dass die .kt-Dateien nicht vorhanden waren. Es wurde kompiliert und konnte daher nicht erkannt werden, als ich versuchte, die App auf dem Gerät zu installieren. Um dieses Problem zu lösen, musste ich nur noch apply plugin: 'kotlin-android' in meinem megle.build hinzufügen, wie in den Links angegeben, auf die er in seinem Kommentar hingewiesen hat, und das ist alles! Es funktioniert jetzt!

Verwandte Themen