第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使 RecyclerView 中的項(xiàng)目可點(diǎn)擊時(shí)出現(xiàn)問題

使 RecyclerView 中的項(xiàng)目可點(diǎn)擊時(shí)出現(xiàn)問題

搖曳的薔薇 2024-01-25 23:05:06
我知道有這樣的問題,但沒有解決我的..我正在嘗試將 'RecyclerView' 設(shè)為 'OnItemClickListener' ,但是當(dāng)我運(yùn)行該應(yīng)用程序時(shí),它停止了。你能告訴我錯(cuò)誤在哪里嗎?這是代碼:(請注意錯(cuò)誤在于使項(xiàng)目可點(diǎn)擊)public class TeacherActivity extends AppCompatActivity {private FirebaseAuth mAuth=FirebaseAuth.getInstance();private FirebaseUser currentUser= mAuth.getCurrentUser();;private FirebaseFirestore db = FirebaseFirestore.getInstance();private String UserId =currentUser.getUid();private static String city;private TeacherAdapter teacherAdapter;public static final String EXTRA_PATH = "com.example.exercise.EXTRA_PATH";@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_teacher);    setUpRecyclerView();  teacherAdapter.setOnItemClickListener(new TeacherAdapter.OnItemClickListener() {  @Override  public void onItemClick(DocumentSnapshot documentSnapshot, int position) {    String path = documentSnapshot.getReference().getPath();    Intent intent = new Intent(TeacherActivity.this, SecondActivity.class);    intent.putExtra(EXTRA_PATH, path);    startActivity(intent);    }    });}// end of onCreateprivate void setUpRecyclerView(){    Query query =   db.collection("Teachers");    FirestoreRecyclerOptions < Teacher > options = new     FirestoreRecyclerOptions.Builder<Teacher>()                            .setQuery(query, Teacher.class)                            .build();    teacherAdapter = new TeacherAdapter(options);    RecyclerView recyclerView = findViewById(R.id.recycler_view);    recyclerView.setHasFixedSize(true);    //for performane reasons    recyclerView.setLayoutManager(new LinearLayoutManager(this));    recyclerView.setAdapter(teacherAdapter);    teacherAdapter.startListening();}@Overrideprotected void onStart() {    super.onStart();}@Overrideprotected void onStop() {    super.onStop();    teacherAdapter.stopListening();}}// end of class
查看完整描述

1 回答

?
慕萊塢森

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

您收到以下錯(cuò)誤:

E/AndroidRuntime:致命異常:主進(jìn)程:com.example.exercise,PID:29966 java.lang.RuntimeException:無法啟動(dòng)活動(dòng) ComponentInfo{com.example.exercise/com.example.exercise.TeacherActivity}:java.lang。 NullPointerException:嘗試在空對象引用上調(diào)用虛擬方法“void com.example.exercise.TeacherAdapter.setOnItemClickListener(com.example.exercise.TeacherAdapter$OnItemClickListener)”

因?yàn)槟谡{(diào)用.setOnItemClickListener()當(dāng)時(shí)的teacherAdapter對象。null要解決這個(gè)問題,您只需移動(dòng)以下代碼塊:

teacherAdapter.setOnItemClickListener(new TeacherAdapter.OnItemClickListener() {

    @Override

    public void onItemClick(DocumentSnapshot documentSnapshot, int position) {


        String path = documentSnapshot.getReference().getPath();

        Intent intent = new Intent(TeacherActivity.this, SecondActivity.class);

        intent.putExtra(EXTRA_PATH, path);

        startActivity(intent);


    }

});

在聲明適配器之后:


teacherAdapter = new TeacherAdapter(options);

按照你的setUpRecyclerView()方法,你的問題就會(huì)得到解決。


查看完整回答
反對 回復(fù) 2024-01-25
  • 1 回答
  • 0 關(guān)注
  • 182 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號