Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正确寻址修复ActivityNotFoundException的意图_Java_Android_Android Intent_Manifest_Activitynotfoundexception - Fatal编程技术网

Java 正确寻址修复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

使用此代码时,我会收到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
        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");