Android Studio TypeAdapter错误,TikXml RSS解析器

问题描述

因此,我一直在尝试解析此reddit RSS提要,并仅在控制台上将其打印出来:reddit rss site

我一直在尝试在Android Studio上对此进行编程,以制作reddit克隆以查看是否可以尝试。我目前收到此错误

2020-10-13 11:05:01.549 11557-11557 / com.example.redditapp E / MainActivity:onFailulre:无法检索RSS:找不到com.example.redditapp.Model.Feed类的TypeAdapter。类型适配器的预期名称为com.example.redditapp.Model.Feed $$ TypeAdapter

我对此感到困惑。这是我的应用到目前为止的样子:

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsversion "30.0.2"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.example.redditapp"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation filetree(dir: "libs",include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //tikxml
    implementation 'com.tickaroo.tikxml:annotation:0.8.13'
    implementation 'com.tickaroo.tikxml:core:0.8.13'
    implementation 'com.tickaroo.tikxml:retrofit-converter:0.8.13'
}

MainActivity.java

package com.example.redditapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.example.redditapp.Model.Feed;
import com.tickaroo.tikxml.tikxml;
import com.tickaroo.tikxml.retrofit.tikxmlConverterFactory;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class MainActivity extends AppCompatActivity {

    public static final String TAG = "MainActivity";

    private static final String BASE_URL = "https://www.reddit.com/r/";

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

        tikxml tikxml = new tikxml.Builder().exceptionOnUnreadxml(false).build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(tikxmlConverterFactory.create(tikxml))
                .build();

        FeedAPI FeedAPI = retrofit.create(FeedAPI.class);

        Call<Feed> call = FeedAPI.getFeed();

        call.enqueue(new Callback<Feed>() {
            @Override
            public void onResponse(Call<Feed> call,Response<Feed> response) {
                Log.d(TAG,"onResponse: Feed: " + response.body().getEntries());
                Log.d(TAG,"onResponse: Server Response: " + response.toString());

            }

            @Override
            public void onFailure(Call<Feed> call,Throwable t) {
                Log.e(TAG,"onFailulre: Unable to retrieve RSS: " + t.getMessage());
                Toast.makeText(MainActivity.this,"An error occured!",Toast.LENGTH_SHORT).show();
            }
        });
    }
}

FeedAPI.java (用于改型的Java接口)

package com.example.redditapp;

import com.example.redditapp.Model.Feed;

import retrofit2.Call;
import retrofit2.http.GET;

public interface FeedAPI {
    String BASE_URL = "https://www.reddit.com/r/";

    @GET("cscareerquestions/.RSS")
    Call<Feed> getFeed();

}

Feed.java (总体xml对象)

package com.example.redditapp.Model;

import com.example.redditapp.Model.Entry.Entry;
import com.tickaroo.tikxml.annotation.Attribute;
import com.tickaroo.tikxml.annotation.Xml;

import java.util.List;

@Xml(name = "Feed")
public class Feed {

    @Attribute(name = "icon")
    public String icon;

    @Attribute(name = "id")
    public String id;

    @Attribute(name = "logo")
    public String logo;

    @Attribute(name = "title")
    public String title;

    @Attribute(name = "updated")
    public String updated;

    @Attribute(name = "subtitle")
    public String subtitle;

    @Attribute(name = "entry")
    public List<Entry> entries;

    //Getters and Setter omitted for conciseness,but implemented in actual program

    @Override
    public String toString(){
        return "Feed:  \n [Entries: \n" + entries + "]";

    }
}

为简洁起见,我不包括我创建的其他子对象,而仅包括我创建的总体对象。对此的任何帮助将不胜感激,因为我一直在四处寻找,却找不到太多关于我遇到的错误或为什么得到它的错误

谢谢大家的光临!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)