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

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

不使用按鈕時(shí),為什么新活動(dòng)不會(huì)從此 OnClick 方法啟動(dòng)?

不使用按鈕時(shí),為什么新活動(dòng)不會(huì)從此 OnClick 方法啟動(dòng)?

我在 Android Studio 中工作,并且正在使用回收器視圖從數(shù)據(jù)庫(kù)創(chuàng)建項(xiàng)目列表。在 RecyclerViewAdapter 中的 OnClick 函數(shù)中,我的目標(biāo)是使用來(lái)自數(shù)據(jù)庫(kù)的額外消息啟動(dòng)一個(gè)新活動(dòng)(該函數(shù)可以正常工作并且在這種情況下不是問(wèn)題)。當(dāng)點(diǎn)擊屏幕時(shí),應(yīng)用程序崩潰而不是加載新活動(dòng)。任何阻止應(yīng)用程序崩潰的幫助將不勝感激。謝謝
查看完整描述

2 回答

?
人到中年有點(diǎn)甜

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

兩個(gè)最可能的問(wèn)題是 (1)eventScreen活動(dòng)未在您的 AndroidManifest.xml 中聲明或 (2)context變量為空。


要解決 (1),請(qǐng)將其添加到您的清單中:


<activity

    android:name=".eventScreen"/>

要解決 (2),請(qǐng)使用ContextViewHolder 的 itemView 中的保證非空:


Context c = v.getContext();

Log.d(TAG, eventName.get(position) + " clicked");

Intent intent = new Intent(c, eventScreen.class);

intent.putExtra("name", eventName.get(position));

c.startActivity(intent);


查看完整回答
反對(duì) 回復(fù) 2021-11-24
?
智慧大石

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

您的數(shù)據(jù)庫(kù)為空,因?yàn)槟鷽](méi)有對(duì)其進(jìn)行初始化。


public class eventScreen extends AppCompatActivity {

    public Database db; // db is NULL

    public TextView name, location, date, website;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_event_screen);

        name = findViewById(R.id.name);

        location = findViewById(R.id.location);

        date = findViewById(R.id.date);

        website = findViewById(R.id.website);


        // You should initialize your DataBase db here before calling loadInfo()


        if (getIntent().hasExtra("name")) {

            String eventName = getIntent().getStringExtra("name");

            loadInfo(eventName);

        }

        else{

            Toast.makeText(this, "No message", Toast.LENGTH_LONG).show();

        }





    }


    public void loadInfo(String title){

        // db is still NULL

        // The crash happens here when you call --> db.getEventData() --> null.getEventData(title)

        String [] info = db.getEventData(title);

        name.setText("the ");

        location.setText("the");

        date.setText("the");

        website.setText("the");

    }

}


查看完整回答
反對(duì) 回復(fù) 2021-11-24
  • 2 回答
  • 0 關(guān)注
  • 140 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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