gpt4 book ai didi

java - 正确处理 Intents 以修复 ActivityNotFoundException

转载 作者:行者123 更新时间:2023-11-29 21:35:44 25 4
gpt4 key购买 nike

当我使用这段代码时,我得到一个 ActivityNotFoundException:

    public void addListenerOnButton3(){

button3 = (Button) findViewById(R.id.btnSettings);
button3.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intentSettings = new Intent("net.stuffilike.kanaflash.Settings");
showToast("Settings clicked,");
try{
startActivity(intentSettings);
}
catch(Exception e){
showToastL("Exception" + e);
}
return;
}
});
}

很公平,除了我不知道它希望我如何告诉它 Activity 在哪里。这是 list 的相关部分:

   <activity
android:name="net.stuffilike.kanaflash.Settings"
android:label="@string/settings" >
<intent-filter>
<action android:name="android.intent.action.SETTINGS" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

我如何确定编译器找到了我的 Settings.java 文件?哦,我的包裹被命名为

package net.stuffilike.kanaflash;

最佳答案

试试这个

@Override
public void onClick(View arg0) {
Intent intentSettings = new Intent(X.this,Settings.class);
showToast("Settings clicked,");
try{
startActivity(intentSettings);
}
catch(Exception e){
showToastL("Exception" + e);
}
return;
}
});

将 X 替换为您当前的 Activity 名称..

关于java - 正确处理 Intents 以修复 ActivityNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18474366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com