Ошибка:E/RecyclerView: No adapter attached; skipping layout
Всем здравствуйте! Я столкнулся с ошибкой:
E/RecyclerView: No adapter attached; skipping layout
Вот мои логи:
02/27 09:21:47: Launching 'app' on motorola AOSP on Shama.
$ adb shell am start -n "com.totrail.totrail/com.totrail.totrail.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 4790 on device 'motorola-aosp_on_shama-127.0.0.1:62001'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
V/FA: Registered activity lifecycle callback
I/FirebaseInitProvider: FirebaseApp initialization successful
W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
V/FA: Deferring to Google Analytics for Firebase for event data collection.
V/FA: Collection enabled
App package, google app id: com.totrail.totrail, 1:769376763866:android:0d1fb07bc3215bf1
I/FA: App measurement is starting up, version: 18102
To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.totrail.totrail
D/FA: Debug-level message logging enabled
I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:21200
Selected remote version of com.google.android.gms.ads.dynamite, version >= 21200
V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
V/FA: Connecting to remote service
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
V/FA: Connection attempt already in progress
V/FA: onActivityCreated
I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
D/Atlas: Validating map...
I/FA: Tag Manager is not found and thus will not be used
D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-3156999787201620692}]
V/FA: Connection attempt already in progress
Connection attempt already in progress
V/FA: Activity resumed, time: 1604022
I/OpenGLRenderer: Initialized EGL, version 1.4
D/: HostConnection::get() New Host Connection established 0xa2c1d520, tid 4823
D/OpenGLRenderer: Enabling debug mode 0
E/RecyclerView: No adapter attached; skipping layout
W/art: Before Android 4.1, method int androidx.appcompat.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
E/RecyclerView: No adapter attached; skipping layout
E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
I/KEK: {"status":"ok","feed":{"url":"http://api.totrail.org:****/feed","title":"ToTrail Personalized Feed","link":"https://totrail.org/","author":"","description":"ToTrail Trails Feed personalized for your account.","image":""},"items":[{"title":"test","pubDate":null,"link":"https://totrail.org/1","guid":"84fcca358becc6bb174b5ac9a3ec7461","author":"","thumbnail":"","description":"None","content":"None","enclosure":{},"categories":[]}]}
Вот мой MainActivity:
package com.totrail.totrail;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.appcompat.app.ActionBarDrawerToggle;
import android.util.Log;
import android.view.MenuItem;
import com.google.android.material.navigation.NavigationView;
import com.google.gson.Gson;
import com.totrail.totrail.Adapter.FeedAdapter;
import com.totrail.totrail.Common.HTTPDataHandler;
import com.totrail.totrail.Model.RSSObject;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.Menu;
import android.view.View;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
RecyclerView recyclerView;
RSSObject rssObject;
private final String RSS_link="http://api.totrail.org:****/feed";
private final String RSS_to_Json_API = "https://api.rss2json.com/v1/api.json?rss_url=";
public static final String APP_PREFERENCES = "voda_zahlebnulas-kolobok_povesilsa";
public static final String APP_PREFERENCES_TOKEN = "token"; // User's API token
public static final String APP_PREFERENCES_STARTED = "nonononono";
public String token = "waiting...";
SharedPreferences mSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Маршруты");
setSupportActionBar(toolbar);
recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getBaseContext(),LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(linearLayoutManager);
loadRSS();
setSupportActionBar(toolbar);
// mAdView = findViewById(R.id.adView);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
// NavigationView navigationView = findViewById(R.id.nav_view);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
// navigationView.setNavigationItemSelectedListener(this);
mSettings = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
mSettings.contains(APP_PREFERENCES_STARTED);// TODO: make very cool welcome screen
// TODO: and here is too! :-)
if(mSettings.contains(APP_PREFERENCES_TOKEN)) {
token = mSettings.getString(APP_PREFERENCES_TOKEN, "");
} else {
token = "not_login_in";
}
}
private void loadRSS() {
@SuppressLint("StaticFieldLeak") AsyncTask<String, String, String> loadRSSAsync = new AsyncTask<String, String, String>() {
ProgressDialog mDialog = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
mDialog.setMessage("Ждите...");
mDialog.show();
}
@Override
protected String doInBackground(String... params) {
String result;
HTTPDataHandler http = new HTTPDataHandler();
result = http.GetHTTPData(params[0]);
return result;
}
@Override
protected void onPostExecute(String s) {
mDialog.dismiss();
Log.i("KEK", s == null ? "null" : s);
rssObject = new Gson().fromJson(s, RSSObject.class);
FeedAdapter adapter = new FeedAdapter(rssObject, getBaseContext());
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
};
StringBuilder url_get_data = new StringBuilder(RSS_to_Json_API);
url_get_data.append(RSS_link);
loadRSSAsync.execute(url_get_data.toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}
// @Override
// protected void onStop() {
// super.onStop();
// Dialog progressDialog = null;
// if ((progressDialog != null) && progressDialog.isShowing()) {
// progressDialog.dismiss();
// progressDialog = null;
// }
// }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_refresh)
loadRSS();
return true;
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
Intent intent = new Intent(this, loginActivity.class);
startActivity(intent);
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_tools) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Вот мой Adapter:
package com.totrail.totrail.Adapter;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.totrail.totrail.Interface.ItemClickListener;
import com.totrail.totrail.Model.RSSObject;
import com.totrail.totrail.R;
class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener{
public TextView txtTitle,txtContent;
private ItemClickListener itemClickListener;
public FeedViewHolder(@NonNull View itemView) {
super(itemView);
txtTitle = itemView.findViewById(R.id.txtTitle);
txtContent = itemView.findViewById(R.id.txtContent);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
@Override
public void onClick(View v) {
itemClickListener.onClick(v,getAdapterPosition(),false);
}
@Override
public boolean onLongClick(View v) {
itemClickListener.onClick(v,getAdapterPosition(),true);
return true;
}
}
public class FeedAdapter extends RecyclerView.Adapter<FeedViewHolder> {
private RSSObject rssObject;
private Context mContext;
private LayoutInflater inflater;
public FeedAdapter(final RSSObject rssObject, Context mContext) {
this.rssObject = rssObject;
inflater = LayoutInflater.from(mContext);
}
@NonNull
@Override
public FeedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = inflater.inflate(R.layout.content_main,parent,false);
return new FeedViewHolder(itemView);
}
@Override
public void onBindViewHolder(FeedViewHolder holder, int position) {
holder.txtTitle.setText(rssObject.getItem().get(position).getTitle());
holder.txtContent.setText(rssObject.getItem().get(position).getDescription());
holder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
if (!isLongClick)
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItem().get(position).getLink()));
mContext.startActivity(browserIntent);
}
}
});
}
@Override
public int getItemCount() {
if (rssObject.item == null) {
return 0;
}
return rssObject.item.size();
}
}
Вот XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_margin="8dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Title"
android:id="@+id/txtTitle"
android:textSize="18sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- <TextView-->
<!-- android:text="Time"-->
<!-- android:id="@+id/txtPubDate"-->
<!-- android:textSize="12sp"-->
<!-- android:textStyle="italic"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"/>-->
<TextView
android:text="Description"
android:id="@+id/txtContent"
android:textSize="14sp"
android:textStyle="normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.cardview.widget.CardView>