java.lang.ClassCastException 上下文错误

大家好,我是使用 Firebase Firestore 在 Android Studio 上开发完整应用程序的新手。我在 youtube 上关注带有 firestores 文档的视频,我想做的只是从我的“Anket”集合中获取所有文档,这是一个调查集合,并将它们列出在弹出屏幕上。感谢您的时间和友好的回答.


MainFragmentActivity.java:


public class MainFragmentActivity extends AppCompatActivity {


    private static final String TAG = "MainActivity";


    private SectionPageAdapter mSectionPageAdapter;


    private ViewPager mViewPager;


    FirebaseAuth mAuth = FirebaseAuth.getInstance();


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main_fragment2);

        Log.d(TAG,"onCreate:Starting");


        mViewPager = findViewById(R.id.container);

        setupViewPager(mViewPager);


        mViewPager.setOffscreenPageLimit(4);


        mSectionPageAdapter = new SectionPageAdapter(getSupportFragmentManager());


        TabLayout tabLayout = findViewById(R.id.tabs);

        tabLayout.setupWithViewPager(mViewPager);

    }


    private void setupViewPager(ViewPager viewPager){

        SectionPageAdapter adapter = new SectionPageAdapter(getSupportFragmentManager());

        adapter.addFragment(new ProfileFragment(), "Profile");

        adapter.addFragment(new MessageFragment(), "Messages");

        adapter.addFragment(new MatchFragment(), "Matches");

        adapter.addFragment(new ShopFragment(), "Shop");

        viewPager.setAdapter(adapter);

    }


    public void logoutUser(View view) {

        mAuth.signOut();

        Intent intent = new Intent (MainFragmentActivity.this, ChooseLoginRegistration.class);

        startActivity(intent);

        finish();

        return;

    }


    public void openUpAnket (View view){

        Intent intent = new Intent(MainFragmentActivity.this,Pop.class);

        startActivity(intent);

    }

}

Pop.java


public class Pop extends Activity implements Serializable {


private FirebaseFirestore surveyDb = FirebaseFirestore.getInstance();



撒科打诨
浏览 71回答 1
1回答

HUX布斯

AnketItemAdapter mAnketItemAdapter = new AnketItemAdapter(this ,mAnketList);这里的this是指OnCompleteListener您创建的实例,而不是Activity(这是一个上下文)。试试Pop.this吧,这将引用外部 Activity 实例。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java