Android NDK:为什么AAssetManager_open返回NULL

豪尔赫·罗德里格斯(Jorge Rodriguez)

我有一些代码:

AAsset* pAsset = AAssetManager_open(pAssetManager, "asset_test.txt", AASSET_MODE_STREAMING);
DebugPrint(pAsset?"pAsset not NULL\n":"pAsset NULL");
if (pAsset)
{
    char buf[1024];
    AAsset_read(pAsset, buf, sizeof(buf));
    DebugPrint(buf);
    AAsset_close(pAsset);
}

此代码始终在logcat中打印“ pAsset NULL”。

我将asset_test.txt文件放在资产目录中,并通过将.apk重命名为.zip并使用7zip打开它来查看.apk,以确保该文件存在。

我还有更多代码:

AAssetDir* pAssetDir = AAssetManager_openDir(pAssetManager, sDirectory.c_str());

if (!pAssetDir)
{
    DebugPrint("pAssetDir NULL\n");
    return;
}

const char* pszDir;
while ((pszDir = AAssetDir_getNextFileName(pAssetDir)) != NULL)
{
    DebugPrint(pszDir);
}

AAssetDir_close(pAssetDir);

此代码不打印任何内容。换句话说,无论我通过什么路径进入资产目录,都找不到文件。

注意:DebugPrint只是__android_log_print()的漂亮包装。

豪尔赫·罗德里格斯(Jorge Rodriguez)

我将Activity传递给了AAssetManager_fromJava(),而我应该传递了AssetManager。如果将错误的类传递给AAssetManager_fromJava(),它将失败,而不会在logcat中打印任何内容。

如何使用JNI获取资产管理器:

    JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();

    jobject activity = (jobject)SDL_AndroidGetActivity();

    jclass activity_class = env->GetObjectClass(activity);

    jmethodID activity_class_getAssets = env->GetMethodID(activity_class, "getAssets", "()Landroid/content/res/AssetManager;");
    jobject asset_manager = env->CallObjectMethod(activity, activity_class_getAssets); // activity.getAssets();
    global_asset_manager = env->NewGlobalRef(asset_manager);

    pAssetManager = AAssetManager_fromJava(env, global_asset_manager);

从现在开始,将该资产管理器指针存放在某个地方,并将其用于所有AAssetManager _ *()函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么意图的Android resolveactivity返回null?

来自分类Dev

为什么我的包裹对象返回为null?Android开发

来自分类Dev

为什么我不能运行任何Android NDK命令?

来自分类Dev

为什么 Android NDK 会错过某些 API 级别?

来自分类Dev

为什么android返回Editable而不是String?

来自分类Dev

Android数学:为什么sum返回1.0?

来自分类Dev

为什么findViewById(R.android.id.home)总是返回null?

来自分类Dev

Android SQLite-为什么Column的字符串返回'null'?

来自分类Dev

android:LruCache返回null

来自分类Dev

Android:findViewById返回null

来自分类Dev

Android ProgressDialog返回null

来自分类Dev

Android UsbAccessory []返回null

来自分类Dev

android:LruCache返回null

来自分类Dev

Android getAllCellInfo()返回null

来自分类Dev

getIntent 返回 null - Android

来自分类Dev

Android NDK java.lang.UnsatisfiedLinkError:启用Multidex后,findLibrary返回null

来自分类Dev

Android NDK open()设备权限被拒绝

来自分类Dev

Android NDK open()设备权限被拒绝

来自分类Dev

Android NDK:为什么arm-linux-androideabi-gdb.exe消失了?

来自分类Dev

在Android NDK代码中#include时,为什么看不到包含路径?

来自分类Dev

为什么在使用OpenSSL的Android NDK中SHA512计算错误

来自分类Dev

为什么在Android NDK上,大于FLT_MAX的浮点数不是无穷大?

来自分类Dev

为什么Android的onCreateOptionsMenu方法返回super.onCreateOptionsMenu?

来自分类Dev

Android:为什么getDimension和getDimensionPixelSize都返回相同的值?

来自分类Dev

为什么从SQlite DB返回的byte []值更改[Android]

来自分类Dev

为什么我在Android中收到Null Pointer异常

来自分类Dev

Android NDK编译错误NDK_PROJECT_PATH = null

来自分类Dev

Android相机照片返回null

来自分类Dev

Android的KeyStore getKey返回null

Related 相关文章

  1. 1

    为什么意图的Android resolveactivity返回null?

  2. 2

    为什么我的包裹对象返回为null?Android开发

  3. 3

    为什么我不能运行任何Android NDK命令?

  4. 4

    为什么 Android NDK 会错过某些 API 级别?

  5. 5

    为什么android返回Editable而不是String?

  6. 6

    Android数学:为什么sum返回1.0?

  7. 7

    为什么findViewById(R.android.id.home)总是返回null?

  8. 8

    Android SQLite-为什么Column的字符串返回'null'?

  9. 9

    android:LruCache返回null

  10. 10

    Android:findViewById返回null

  11. 11

    Android ProgressDialog返回null

  12. 12

    Android UsbAccessory []返回null

  13. 13

    android:LruCache返回null

  14. 14

    Android getAllCellInfo()返回null

  15. 15

    getIntent 返回 null - Android

  16. 16

    Android NDK java.lang.UnsatisfiedLinkError:启用Multidex后,findLibrary返回null

  17. 17

    Android NDK open()设备权限被拒绝

  18. 18

    Android NDK open()设备权限被拒绝

  19. 19

    Android NDK:为什么arm-linux-androideabi-gdb.exe消失了?

  20. 20

    在Android NDK代码中#include时,为什么看不到包含路径?

  21. 21

    为什么在使用OpenSSL的Android NDK中SHA512计算错误

  22. 22

    为什么在Android NDK上,大于FLT_MAX的浮点数不是无穷大?

  23. 23

    为什么Android的onCreateOptionsMenu方法返回super.onCreateOptionsMenu?

  24. 24

    Android:为什么getDimension和getDimensionPixelSize都返回相同的值?

  25. 25

    为什么从SQlite DB返回的byte []值更改[Android]

  26. 26

    为什么我在Android中收到Null Pointer异常

  27. 27

    Android NDK编译错误NDK_PROJECT_PATH = null

  28. 28

    Android相机照片返回null

  29. 29

    Android的KeyStore getKey返回null

热门标签

归档