Android应用打开网页时遇到问题

时间:2015-02-25 00:15:14

标签: android

我的Android应用程序存在一些问题。其他一切都在工作,除非我去尝试将我带到网站的列表,模拟器停止工作。



package net.androidbootcamp.cityguide;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String[] attraction={"Alcatraz Island", "Ferry Marketplace", "Golden Gate Bridge", "Cable Car Trolley", "Fisherman's Wharf"};
		setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_main,R.id.travel, attraction));
	}
	protected void onListItemClick(ListView i, View v, int position, long id){
		switch(position){
		case 0:
			startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://alcatrazcruises.com/")));
			break;
		case 1:
			startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.farrybuildingmarketplace.com")));
			break;
		case 2:
			startActivity(new Intent(MainActivity.this, Bridge.class));
			break;
		case 3:
			startActivity(new Intent(MainActivity.this, Trolley.class));
			break;
		case 4:
			startActivity(new Intent(MainActivity.this, Wharf.class));
			break;
		}
	}

	@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;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
&#13;
&#13;
&#13;

这是主要的活动代码,我在日志中遇到的错误是

02-24 19:14:32.406: E/AndroidRuntime(1038): FATAL EXCEPTION: main
02-24 19:14:32.406: E/AndroidRuntime(1038): Process: net.androidbootcamp.cityguide, PID: 1038
02-24 19:14:32.406: E/AndroidRuntime(1038): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://www.farrybuildingmarketplace.com }
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.Activity.startActivityForResult(Activity.java:3736)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.Activity.startActivityForResult(Activity.java:3697)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.Activity.startActivity(Activity.java:4007)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.Activity.startActivity(Activity.java:3975)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at net.androidbootcamp.cityguide.MainActivity.onListItemClick(MainActivity.java:28)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.widget.AdapterView.performItemClick(AdapterView.java:300)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.widget.AbsListView.performItemClick(AbsListView.java:1143)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3044)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.widget.AbsListView$3.run(AbsListView.java:3833)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.os.Handler.handleCallback(Handler.java:739)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.os.Handler.dispatchMessage(Handler.java:95)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.os.Looper.loop(Looper.java:135)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at android.app.ActivityThread.main(ActivityThread.java:5221)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at java.lang.reflect.Method.invoke(Native Method)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at java.lang.reflect.Method.invoke(Method.java:372)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-24 19:14:32.406: E/AndroidRuntime(1038):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我不能100%确定我应该如何添加错误日志。我希望这有效。

1 个答案:

答案 0 :(得分:0)

您的模拟器没有安装Web浏览器,当您尝试打开它时,您的应用程序崩溃了。

启动Web浏览器时添加异常处理程序以避免崩溃。

try {
           startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://website.com/")));
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, "App not found", Toast.LENGTH_LONG).show();  
    }