RecyclerView:没有连接适配器;跳过布局

时间:2015-06-16 20:44:40

标签: android json parse-platform android-adapter android-recyclerview

我的应用程序正在从Parse.com正确获取信息,但没有像以前那样在recyclerview中正确显示信息。我被提示错误消息"没有连接适配器;跳过布局"而且Recyclerview仍然是空的。您能否查看我的计划并通知我我可能错过的任何错误?

$





package com.example.jbobo_000.prac;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;


import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;

import java.util.ArrayList;
import java.util.List;

public class HomeScreen extends AppCompatActivity {
    private RecyclerView mRecyclerDrawer;
    private customAdapter mAdapter;
    private Context context;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_screen);
        setupDrawer();
        context=this;
        final List<Information> data = new ArrayList<>();
        Parse.initialize(this, "XXXXXXXXXXXXXXX", "XXXXXXXXXXXXX");
        ParseQuery<ParseObject> query = ParseQuery.getQuery("flyerDataFetch");
        query.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> results, com.parse.ParseException e) {
                if (e == null) {
                    for (ParseObject a : results) {

                        Information information = new Information();
                        information.partyName = a.getString("partyName");
                        information.partyPromoterName = a.getString("partyPromoterName");
                        information.partyCost = a.getString("partyCost");
                        // information.flyerPic = a.getParseFile("partyFlyerImage");

                        //information.partyPromoterPic = a.getParseFile("partyFlyerImage");


                        data.add(information);

                    }
                } else {
                    // something went wrong
                }
                mRecyclerDrawer = (RecyclerView) findViewById(R.id.drawerList);
                mRecyclerDrawer.setLayoutManager(new LinearLayoutManager(context));
                mAdapter = new customAdapter(getApplicationContext(), data);
                mRecyclerDrawer.setAdapter(mAdapter);
                mAdapter.notifyDataSetChanged();
            }

        });
    }


    private void setupDrawer() {
        Toolbar mToolbar;
        NavigationDrawer mDrawerFragment;
        mToolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        //setup the NavigationDrawer

        mDrawerFragment = (NavigationDrawer)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        mDrawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
}

$

    package com.example.jbobo_000.prac;



    import android.content.Context;
    import android.content.Intent;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.TextView;

    import com.parse.ParseImageView;

    import java.util.Collections;
    import java.util.List;

    public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder> {
        List<Information> data = Collections.emptyList();
        private LayoutInflater inflater;
        private Context context;
        public customAdapter (Context context,List<Information>data){
            this.context=context;
            inflater=LayoutInflater.from(context);
            this.data= data;
        }

       @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
           View view= inflater.inflate(R.layout.custom_row, parent, false);
           MyViewHolder holder = new MyViewHolder(view);
           return holder;
       }

        @Override
        public void onBindViewHolder(MyViewHolder holder,int position){
            Information current= data.get(position);
            holder.promoterNameText.setText(current.partyPromoterName);
            holder.costText.setText(current.partyCost);
            holder.partyNameText.setText(current.partyName);
            holder.flyerImage.setParseFile(current.flyerPic);
            holder.promoterImage.setParseFile(current.partyPromoterPic);
        }

        @Override
        public int getItemCount(){

            return data.size();
        }


        class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
            TextView promoterNameText;
            TextView costText;
            TextView partyNameText;
            ParseImageView flyerImage;
            ParseImageView promoterImage;

            public MyViewHolder(View itemView) {
                super(itemView);
                itemView.setOnClickListener(this);
                promoterImage = (ParseImageView) itemView.findViewById(R.id.promoterPicImage);
                flyerImage = (ParseImageView) itemView.findViewById(R.id.flyertImage);
                costText = (TextView) itemView.findViewById(R.id.costText);
                promoterNameText = (TextView) itemView.findViewById(R.id.promoterNameText);
                partyNameText = (TextView) itemView.findViewById(R.id.partyNameText);
            }

            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, partyInformation.class));

            }
        }
    }

$

06-16 16:42:35.119    2230-2230/? I/art﹕ Late-enabling -Xcheck:jni
06-16 16:42:35.261    2230-2230/? D/CrashReporting﹕ Crash reporting is enabled for com.example.jbobo_000.prac, initializing...
06-16 16:42:35.292    2230-2230/? D/CrashReporting﹕ Looking for error files in /data/data/com.example.jbobo_000.prac/files/com.parse/cr/reports
06-16 16:42:35.296    2230-2230/? D/CrashReporting﹕ Looking for error files in /data/data/com.example.jbobo_000.prac/files/com.parse/cr/minidumps
06-16 16:42:35.484    2230-2260/? D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-16 16:42:35.488    2230-2230/? D/﹕ HostConnection::get() New Host Connection established 0xb3ec9ac0, tid 2230
06-16 16:42:35.498    2230-2230/? D/Atlas﹕ Validating map...
06-16 16:42:35.554    2230-2260/? D/libEGL﹕ loaded /system/lib/egl/libEGL_emulation.so
06-16 16:42:35.555    2230-2260/? D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_emulation.so
06-16 16:42:35.568    2230-2260/? D/libEGL﹕ loaded /system/lib/egl/libGLESv2_emulation.so
06-16 16:42:35.579    2230-2260/? D/﹕ HostConnection::get() New Host Connection established 0xaf0395c0, tid 2260
06-16 16:42:35.600    2230-2260/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-16 16:42:35.655    2230-2260/? D/OpenGLRenderer﹕ Enabling debug mode 0
06-16 16:42:35.676    2230-2260/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
06-16 16:42:35.676    2230-2260/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xaf035b40, error=EGL_SUCCESS
06-16 16:42:37.786    2230-2230/com.example.jbobo_000.prac I/ViewUtils﹕ app:theme is now deprecated. Please move to using android:theme instead.
06-16 16:42:38.132    2230-2260/com.example.jbobo_000.prac W/EGL_emulation﹕ eglSurfaceAttrib not implemented
06-16 16:42:38.132    2230-2260/com.example.jbobo_000.prac W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3edd980, error=EGL_SUCCESS
06-16 16:42:38.167    2230-2230/com.example.jbobo_000.prac E/RecyclerView﹕ No adapter attached; skipping layout
06-16 16:42:38.524    2230-2230/com.example.jbobo_000.prac E/RecyclerView﹕ No adapter attached; skipping layout
06-16 16:42:40.723    2230-2230/com.example.jbobo_000.prac D/AndroidRuntime﹕ Shutting down VM
06-16 16:42:40.724    2230-2230/com.example.jbobo_000.prac E/CrashReporting﹕ ParseCrashReporting caught a AndroidRuntimeException exception for com.example.jbobo_000.prac. Building report.
06-16 16:42:40.725    2230-2230/com.example.jbobo_000.prac E/CrashReporting﹕ Handling exception for crash
    android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
            at android.app.ContextImpl.startActivity(ContextImpl.java:1246)
            at android.app.ContextImpl.startActivity(ContextImpl.java:1233)
            at android.content.ContextWrapper.startActivity(ContextWrapper.java:323)
            at com.example.jbobo_000.prac.customAdapter$MyViewHolder.onClick(customAdapter.java:72)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
06-16 16:42:40.725    2230-2230/com.example.jbobo_000.prac D/CrashReporting﹕ Generating report file for crash
06-16 16:42:40.794    2230-2230/com.example.jbobo_000.prac D/CrashReporting﹕ Retrieving logcat output...
06-16 16:42:40.809    2230-2230/com.example.jbobo_000.prac D/CrashReporting﹕ Retrieving logcat output...
06-16 16:42:40.827    2230-2230/com.example.jbobo_000.prac D/CrashReporting﹕ Retrieving logcat output...
06-16 16:42:40.885    2230-2230/com.example.jbobo_000.prac W/Settings﹕ Setting stay_on_always has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
06-16 16:42:41.051    2230-2230/com.example.jbobo_000.prac V/CrashReporting﹕ About to start ReportSenderWorker from #handleException
06-16 16:42:41.055    2230-2326/com.example.jbobo_000.prac D/CrashReporting﹕ #checkAndSendReports - start
06-16 16:42:41.056    2230-2326/com.example.jbobo_000.prac D/CrashReporting﹕ Looking for error files in /data/data/com.example.jbobo_000.prac/files/com.parse/cr/reports
06-16 16:42:41.057    2230-2326/com.example.jbobo_000.prac D/CrashReporting﹕ Loading file 1434487360725-AndroidRuntimeException-1.stacktrace
06-16 16:42:41.063    2230-2326/com.example.jbobo_000.prac I/CrashReporting﹕ Sending file 1434487360725-AndroidRuntimeException-1.stacktrace
06-16 16:42:41.063    2230-2326/com.example.jbobo_000.prac D/CrashReporting﹕ Sending crash report to Parse...
06-16 16:42:41.070    2230-2326/com.example.jbobo_000.prac D/CrashReporting﹕ #checkAndSendReports - finish
06-16 16:42:41.153    2230-2230/com.example.jbobo_000.prac E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.jbobo_000.prac, PID: 2230
    android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
            at android.app.ContextImpl.startActivity(ContextImpl.java:1246)
            at android.app.ContextImpl.startActivity(ContextImpl.java:1233)
            at android.content.ContextWrapper.startActivity(ContextWrapper.java:323)
            at com.example.jbobo_000.prac.customAdapter$MyViewHolder.onClick(customAdapter.java:72)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

1 个答案:

答案 0 :(得分:2)

您的错误日志中没有错误:没有连接适配器;跳过布局

仅限: android.util.AndroidRuntimeException:从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志。这真的是你想要的吗?

为避免这种情况,只需更改:

mAdapter = new customAdapter(getApplicationContext(), data);

mAdapter = new customAdapter(this, data);