【问题标题】:Class Recognition; R.drawable.balloons班级认可; R.drawable.balloons
【发布时间】:2014-05-30 21:36:32
【问题描述】:

好的,我似乎对 R.drawable.balloons 有一个小问题。我正在尝试使用模板来构建我在 Android Developer 上找到的私有外部存储文件,但气球不断给出错误(无法解析或不是字段)。我想知道是否可以得到一些帮助来修复它。

这是它所在的代码部分:

void createExternalStoragePrivateFile() {
        // Create a path where we will place our private file on external
        // storage.
    File file = new File(getExternalFilesDir(null), "DemoFile.jpg");

    try {
            /*  
                Very simple code to copy a picture from the application's
                resource into the external file.  Note that this code does
                no error checking, and assumes the picture is small (does not
                try to copy it in chunks).  Note that if external storage is
                not currently mounted this will silently fail.
            */

            //  Creates file to stream picture
        OutputStream os = new FileOutputStream(file);
            //  Allows app to accept the picture
        InputStream is = getResources().openRawResource(R.drawable.balloons);
        byte[] data = new byte[is.available()];
        is.read(data);
        os.write(data);
        is.close();
        os.close();
    } catch (IOException e) {
            // Unable to create file, likely because external storage is
            // not currently mounted.
        Log.w("ExternalStorage", "Error writing " + file, e);
    }
}

请注意,如果我因为复制/粘贴而被点名,这应该只是一个模板,但我想在进行更改之前测试它是否有效。对不起。

【问题讨论】:

    标签: android r.java-file


    【解决方案1】:

    您需要在项目的res\drawable 文件夹(或其任何变体,例如drawable-hdpi,&c)中有一个名为balloons 的图像。 R 类是自动生成的。

    How do I add R drawable android?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多