Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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
Android Studio隐含意图基本问题_Android - Fatal编程技术网

Android Studio隐含意图基本问题

Android Studio隐含意图基本问题,android,Android,我正在学习安卓基础02.3:隐含意图,我遵循这些步骤,但无法处理意图。 这是我写的: public void openWebsite(View view) { String url = mWebsiteEditText.getText().toString(); Uri webpage = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, webpage); if (intent.

我正在学习安卓基础02.3:隐含意图,我遵循这些步骤,但无法处理意图。 这是我写的:

   public void openWebsite(View view) {
    String url = mWebsiteEditText.getText().toString();
    Uri webpage = Uri.parse(url); 
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
    if (intent.resolveActivity(getPackageManager()) != null) {  
    startActivity(intent);
    }else{
        Log.d("ImplicitIntents", "Can't handle this!");
    }
}
这是我被告知要写的:

public void openWebsite(View view) {
        // Get the URL text.
        String url = mWebsiteEditText.getText().toString();

        // Parse the URI and create the intent.
        Uri webpage = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

        // Find an activity to hand the intent and start that activity.
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Log.d("ImplicitIntents", "Can't handle this!");
        }
    }
但我就是跑不动

D/ImplicitIntents: Can't handle this!
我尝试的是:

当我下载正式项目并构建时,它可以正常工作。 当我删除“如果”时,它起作用:

public void openWebsite(View view) {
        String url = mWebsiteEditText.getText().toString();
        Uri webpage = Uri.parse(url); 
        Intent intent = new Intent(Intent.ACTION_VIEW, webpage); 
        startActivity(intent);
    }

问题是,为什么会发生这种情况?

您使用什么设备进行测试?您是否尝试使用调试器查看发生了什么?