2014-06-20 71 views
0

当我点击button1打开浏览器的url时,应用程序停止。和调试我得到这个错误:Android应用试图打开网页浏览器时停止

 ![throw new ActivityNotFoundException(][1] 
       "No Activity found to handle " + intent); 

这是代码:

package com.example.outroprojeto; 
//   
import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class AtividadePrincipal extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_atividade_principal); 
     addButtonClickListner(); 
    } 
    public void addButtonClickListner() 
    { 

     Button btnNavigator = (Button)findViewById(R.id.button1); 
     btnNavigator.setOnClickListener(new OnClickListener(){ 
      public void onClick(View arg) 
      { 

       Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.satalaj.com")); 
       startActivity(intent); 
      } 
     }); 
    } 


} 

在这里,你能够看见的调试屏幕

+0

你在模拟器中测试吗? – Pankaj

+0

你没有浏览器,错误说什么,但我怀疑这个代码对我完全作品 –

+0

感谢Pankaj问题是模拟器。 –

回答

0

尝试使用XML。在Xml中创建按钮并添加android:onClick =“browseWeb”,然后在Java活动中添加以下代码。

public void brosweWeb (View view) { 
Intent intent = new Intent(Intent.ACTION_VIEW 
Uri.parse("web address here")); 
startActivity(intent); 
相关问题