gpt4 book ai didi

java - 在 Android 中调用游标时收到 NullPointerException

转载 作者:行者123 更新时间:2023-12-01 05:57:20 25 4
gpt4 key购买 nike

我正在创建一个应用程序,它使用 GPS 跟踪用户位置,使用内容提供程序将经度和纬度存储在数据库中,然后将第一个经度和纬度输出到 map View 。

我可以使用这行代码创建光标:

Cursor c = getContentResolver().query(GPSContentProvider.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);

但是,当我调用移动到数据库中的第一行,甚至尝试使用 c.close(); 关闭游标时,我收到 NullPointerException

编辑:为了说清楚,我可以将经度、纬度和时间以毫秒为单位存储在数据库中,问题是从数据库中取出数据并将其显示在 map 上。

更新的代码:

public static final String AUTHORITY = "application.android.prototype";
// followed by the CONTENT_URI
public static final Uri CONTENT_URI = Uri.
parse("content://" + AUTHORITY + "/gpspoints");

更新的权限:

<provider android:name="GPSDataContentProvider" android:authorities="application.android.prototype">
</provider>

最佳答案

我最终决定不使用 ContentProvider,因为我的应用程序的数据库仅由该单个应用程序使用。

相反,我使用 SQL 创建了一个典型的数据库并使用了类似的 Cursor 函数:

SQLiteDatabase db = waypoints.getReadableDatabase(); 游标cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY); 开始管理光标(光标); 返回光标;

关于java - 在 Android 中调用游标时收到 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2472402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com