Java 正确寻址修复ActivityNotFoundException的意图
使用此代码时,我会收到ActivityNotFoundException:Java 正确寻址修复ActivityNotFoundException的意图,java,android,android-intent,manifest,activitynotfoundexception,Java,Android,Android Intent,Manifest,Activitynotfoundexception,使用此代码时,我会收到ActivityNotFoundException: public void addListenerOnButton3(){ button3 = (Button) findViewById(R.id.btnSettings); button3.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { Intent inte
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
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>
试试这个
@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替换为当前活动名称。有两种方法可以做到这一点
字符串
让系统看到活动
s可以解决意图
上的操作。如果有多个活动
可以解决该操作,则用户将获得一个选项来选择他们想要的活动
Intent intentSettings = new Intent("android.intent.action.SETTINGS");
活动
(仅当两个活动
在同一个应用程序中时才能执行)
新意图(字符串操作)
的构造函数将操作作为参数
根据清单,您使用的操作是android.intent.action.SETTINGS
1.所以你的意图如下
Intent intentSettings = new Intent("android.intent.action.SETTINGS");
或
2.您可以使用活动名称直接调用活动
Intent intentSettings = new Intent(this, Settings.class);
或
3.您还可以定义自定义操作,如net.stuffilike.intent.action.SETTINGS
,然后使用它创建intent
等
Intent intentSettings = new Intent("net.stuffilike.intent.action.SETTINGS");
就这样!非常感谢你。
Intent intentSettings = new Intent(this, Settings.class);
Intent intentSettings = new Intent("net.stuffilike.intent.action.SETTINGS");