2013-09-26 47 views
10

我試圖做一些簡單的事情,比如從我的應用程序打開網頁。我覺得代碼看起來應該低於looke,但我不斷收到錯誤「無活動」,而執行代碼:我不斷收到錯誤「找不到處理意圖的活動」

public class MainActivity extends Activity { 
    public static final String MY_STRING = "com..example.MY_STRING"; 
    Button button1; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     button1 = (Button) findViewById(R.id.button1); 
     button1.setOnClickListener(clickListener); 

    }  
    public OnClickListener clickListener = new OnClickListener(){   
     @Override 
     public void onClick(View arg0) { 

      Intent launchBrowser = new Intent(Intent.ACTION_VIEW, Uri.parse("www.example.com"));     
      startActivity(launchBrowser);    
     }   
    };  
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 

這裏是日誌:

D/libEGL(11574): loaded /system/lib/egl/libGLES_android.so 
D/libEGL(11574): loaded /vendor/lib/egl/libEGL_mtk.so 
D/libEGL(11574): loaded /vendor/lib/egl/libGLESv1_CM_mtk.so 
D/libEGL(11574): loaded /vendor/lib/egl/libGLESv2_mtk.so 
D/OpenGLRenderer(11574): Enabling debug mode 0 
V/Provider/Setting(11574): invalidate [system]: current 109 != cached 0 
D/AndroidRuntime(11574): Shutting down VM 
W/dalvikvm(11574): threadid=1: thread exiting with uncaught exception (group=0x40ca8258) 
E/AndroidRuntime(11574): FATAL EXCEPTION: main 
E/AndroidRuntime(11574): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.example.com } 
E/AndroidRuntime(11574): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1518) 
E/AndroidRuntime(11574): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1390) 
E/AndroidRuntime(11574): at android.app.Activity.startActivityForResult(Activity.java:3204) 
E/AndroidRuntime(11574): at android.app.Activity.startActivity(Activity.java:3311) 
E/AndroidRuntime(11574): at com.example.openwebpage.MainActivity$1.onClick(MainActivity.java:40) 
E/AndroidRuntime(11574): at android.view.View.performClick(View.java:3517) 
E/AndroidRuntime(11574): at android.view.View$PerformClick.run(View.java:14155) 
E/AndroidRuntime(11574): at android.os.Handler.handleCallback(Handler.java:605) 
E/AndroidRuntime(11574): at android.os.Handler.dispatchMessage(Handler.java:92) 
E/AndroidRuntime(11574): at android.os.Looper.loop(Looper.java:137) 
E/AndroidRuntime(11574): at android.app.ActivityThread.main(ActivityThread.java:4503) 
E/AndroidRuntime(11574): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(11574): at java.lang.reflect.Method.invoke(Method.java:511) 
E/AndroidRuntime(11574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) 
E/AndroidRuntime(11574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 
E/AndroidRuntime(11574): at dalvik.system.NativeStart.main(Native Method) 

,這裏是我的清單:

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.openwebpage.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

+0

你可以試試'Uri.parse(「http://www.example.com」)'? –

+0

你可以試試Uri.parse(「http:// www。google.com」)嗎? – Turkish

+1

只需在您的網址 – Houcine

回答

23

只是猜測,但你可能會錯過前綴http://。嘗試

Intent launchBrowser = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); 
+0

上加上'http://',與「http://」 – user696847

+1

同樣的東西很奇怪。尋找類似的帖子,這一個建議url方案實際上是問題。 http://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application最後一次更改沒有編譯的機會?另外,你有沒有嘗試過類似http://www.google.com的內容? – ssantos

+0

我曾嘗試使用google.com,但我的應用程序甚至不啓動瀏覽器。它在點擊事件(啓動瀏覽器)時崩潰。所以它不能解決url問題。 – user696847

2

正確的方法是通過瀏覽器推出一個網站是

Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com")); 
startActivity(viewIntent); 
1

出於某種原因,現在它正在與那些添加的「http://」

後,我重新啓動設備,並再次運行它添加「http://」它成功了。

0

有時大寫會導致該問題。儘量使URL小寫。

相關問題