我创建了下面简单的代码从浏览器中获得书签:
public class BroswerProviderActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Cursor cursor = getContentResolver().query(Browser.BOOKMARKS_URI, null, null, null, null);
String s[] = new String[]{
Browser.BookmarkColumns.BOOKMARK,
Browser.BookmarkColumns.TITLE};
int view[] = new int[]{
R.id.Bookmark, R.id.title};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.main, cursor, s, view);
this.setListAdapter(adapter);
}
}
我也在manifest文件中添加了权限:
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS">
但是当我运行这个程序时,不能执行,显示一些错误,要求强制停止程序。如何解决这个问题?
这是我从LogCat窗口中获得的异常,但是这是不相关的:
我创建的XML文件:
<ListView android:transcriptMode="normal" android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.0"></ListView>
<TextView android:text="TextView" android:id="@+id/bookmark" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="TextView" android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
1.你如果要继承ListActivity,就不需要setContentView().去掉setContentView(R.layout.main);
程序就可以运行了
2.你如果要用main,把extends ListActivity 改成extends Activity,然后去findViewById那个ListView再设置adapter