简体   繁体   English

找不到Android资源异常。 通过字符串指定资源

[英]Android resource not found exception. Specify a resource by string

package com.example.tictactoe3d;

import min3d.core.Object3dContainer;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;

import min3d.vos.Light;

public class MainActivity extends RendererActivity {

    private Object3dContainer objModel;

    @Override
    public void initScene() {

        scene.lights().add(new Light());

        IParser parser = Parser.createParser(Parser.Type.OBJ,getResources(), "res/raw/camaro_obj" , true);
        parser.parse();

        objModel = parser.getParsedObject();
        //objModel.scale().x = objModel.scale().y = objModel.scale().z = .7f;
        scene.addChild(objModel);
    }

    @Override
    public void updateScene() {
        //objModel.rotation().x++;
        //objModel.rotation().z++;
        scene.camera().position.setAll(0,0,5);
    }
}

I am getting a resource not found exception coming out into the log of Eclipse ADT. 我在Eclipse ADT的日志中遇到了找不到资源的异常。 The min3d library I am using requires to access the resource with a string. 我正在使用的min3d库要求使用字符串访问资源。 I am able to access the resource using R.raw.camaro_obj with the auto complete however the min3d library wants to access that same resource with a string. 我可以使用具有自动完成功能的R.raw.camaro_obj访问资源,但是min3d库希望使用字符串来访问相同的资源。 I have tried: 我努力了:

"com.example.tictactoe3d:raw/camaro_obj"

"res/raw/camaro_obj"

"raw/camaro_obj"

Is there some way to access the resource "res/raw/camaro_obj" by string somehow? 是否可以通过某种方式通过字符串访问资源“ res / raw / camaro_obj”?

Thanks... 谢谢...

The call in min3d sample project looks like this: min3d示例项目中的调用如下所示:

        IParser parser = Parser.createParser(Parser.Type.OBJ,getResources(), "min3d.sampleProject1:raw/test2_obj" , true);

The code that is actually called by that line is doing this: 该行实际调用的代码正在执行此操作:

    public AParser(Resources resources, String resourceID, Boolean generateMipMap)
{
    this();
    this.resources = resources;
    this.resourceID = resourceID;
    if (resourceID.indexOf(":") > -1)
        this.packageID = resourceID.split(":")[0];
    this.generateMipMap = generateMipMap;
}

You normally don't use a string, you access them by id. 通常,您不使用字符串,而是通过id访问它们。 R.raw.camaro_obj will be an int and you can get an input stream to it by calling getResources().openRawResources(R.raw.camaro_obj); R.raw.camaro_obj将是一个int,您可以通过调用getResources().openRawResources(R.raw.camaro_obj);来获得输入流getResources().openRawResources(R.raw.camaro_obj);

Edit: 编辑:

I did some googling, this http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html may help 我做了一些谷歌搜索,这http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html可能会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM