编译ANDROID , ECLIPSE编译通过,ANDROID手机上运行报 Get data from file(assets/XXX) failed

小弟自己的项目编译ANDROID , ECLIPSE编译通过,ANDROID手机上运行报 Get data from file(assets/XXX) failed

检查代码发现是Animatepacker.cpp中的 void AnimatePacker::loadAnimations(const std::string &path )

函数中报的错,

fullPathFromRelativePath函数我已经检查了cocos2dx 2.0.4 会返回正确地指针,应该不存在网络上所说的版本问题.

const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return pszRelativePath;
}

Animatepacker中只要执行这一句parser.parse(pszPath),程序就会出错.

我检查了传入Animatepacker中的路径没有问题, 不知道各位大虾有没有解决办法,.真心谢过了。

附出错函数代码,红色执行会报:Get data from file(assets/XXX) failed
void AnimatePacker::loadAnimations(const std::string &path )
{
//const char *pszPath = CCFileUtils::sharedFileUtils()->CCFileUtils::fullPathFromRelativePath(path);
const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(path.c_str());

CCSAXParser parser;
AnimateSaxDelegator delegator;
if (false == parser.init(“UTF-8”))
{
//TODO
return;
}
parser.setDelegator(&delegator);
parser.parse(pszPath);

//load plist
vector plists=delegator.plists;
for (unsigned int i=0;i<plists.size();i++)
{
string plistPath = CCFileUtils::sharedFileUtils()->CCFileUtils::fullPathFromRelativeFile(plists.c_str(), pszPath);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistPath.c_str());
}
//load animate
vector animates=delegator.animates;
CCArray *spriteFramesArray = new CCArray();
set animateNames;
for (unsigned int i=0;i<animates.size();i++)
{
Animate animate=animates;
vector spriteFrames=animate.spriteFrames;
for (unsigned int j=0;j<spriteFrames.size();j++)
{
animateNames.insert(spriteFrames);
CCSpriteFrame *spriteFrame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrames.c_str());
spriteFramesArray->addObject(spriteFrame);
}
CCAnimation *animation=CCAnimation::animationWithSpriteFrames(spriteFramesArray,animate.delay);
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,animate.name.c_str());
spriteFramesArray->removeAllObjects();
}

//record animate
for(unsigned int i=0;i<animates.size();i++){
Animate animate=animates;
nameToAnimateMap=animate;
}
//record plist
pathToPlistsMap=plists;
//record CCAnimate name
pathToNameMap=animateNames;
}

把resource资源文件夹下的东西移动到android/assets/目录下即可。这个原因主要是权限不够的问题。

版主大哥,首先非常感谢你的帮助,但我试了还是不行,我把项目里RESOURCE里的文件都COPY到assets/目录下 还是那个错误.

而且我程序在加载报错的XML文件前,还加载了一个PLIST就没报错,(加载用的CLASS不一样).

附小米手机报错截图一张.我的文件叫SHADOW.XML,报错的信里前边出了一大堆EDEDED,不知道什么原因,是不是这个引起的错误?

谢谢.

你打印下系统返回的文件目录吧,看下是这个路径返回就有问题还是被某个地方改动了,我这还没遇到过这个问题。

现在还有另外一个问题,就是我在ANDROID了解析不出TILEMAP里定义的POLYLINE,在WIN32里可以正常解析.我解析POLYLINE的代码如下.

能否帮我看下,是不是哪些函数ANDROID不支持? 非常感谢.(我之前代码里用了ATOF我怕ANDROID不支持,现在改成了SSCANF,但还是不行)

void GBBox2d::Box2DTileMapContact(CCTMXTiledMap* map,CCSprite* spriteblock)
{
CCTMXObjectGroup* objectGroup = map->objectGroupNamed(“OBJECT”);

CCArray* objects = (CCArray*)objectGroup->getObjects() ;

CCDictionary* objectsdict = NULL;
CCObject* pObj = NULL;    
CCARRAY_FOREACH(objects, pObj)
{   
    //定义形状
    //b2PolygonShape* Shape = new b2PolygonShape();
    b2EdgeShape* Shape=new b2EdgeShape();

    objectsdict= (CCDictionary*)pObj;
    if(!objectsdict)
    break;        
    
    //获取原点X坐标
    CCString* pointx = (CCString*)objectsdict->valueForKey("x") ;
    char* cpointx = (char*)pointx->getCString() ;
    //float fpointx = atof(cpointx) ;
    //fpointx = 50 ;
    float fpointx = 0 ;
    sscanf(cpointx,"%f",&fpointx) ;

    //sprintf(animationnumber, "%d", spritetoxx); 


    //获取原点Y坐标
    CCString* pointy = (CCString*)objectsdict->valueForKey("y") ;
    char* cpointy = (char*)pointy->getCString() ;
    float fpointy = 0 ;
        //atof(cpointy) ;
    sscanf(cpointy,"%f",&fpointy) ;
    //fpointy = 50 ;

    //获取遮挡增量坐标
    CCString* points = (CCString*)objectsdict->valueForKey("points") ;
    char* cpoints = (char*)points->getCString() ;
    strcat(cpoints,"ED") ; 
    int i = 0 ;
    int num = 0 ;
    int flag = 0 ;
    int changeflg = 0 ;
    string xy= "" ;
    string x="" ;
    string y="" ; 
    b2Vec2 verts ; 
    while(*(cpoints+i)!='D')
    {        
        //当遇空格或逗号时表示改变,遇E时表示最后
        if(*(cpoints+i) == ' '||*(cpoints+i) == ','||*(cpoints+i) == 'E')
        {
            if(flag ==0 )
                flag = 1;
            else 
                flag = 0 ;
            changeflg = 1 ;
            i++ ;
            
        }
        //发生改变
        if(xy != "" && changeflg == 1)
        {
            //记录Y值
            if(flag == 0 )
            {
                y = xy ;
                //记录XY值并转换为刚体
                if( x!="" && y!="" )
                {    
                    num++ ;
                    float datax = 0 ;
                    float datay = 0 ;
                    sscanf(x.data(),"%f",&datax) ;
                    sscanf(y.data(),"%f",&datay) ;
                    float fx = fpointx + datax;
                    float fy = fpointy - datay;
                    verts = b2Vec2(fx/PTM_RATIO*mapscale, fy/PTM_RATIO*mapscale);    
                    //verts.x = fx/PTM_RATIO ;
                    //verts.y = fy/PTM_RATIO ;
                }
            }
            //记录X值
            else
            {
                x = xy ;
            }
            changeflg = 0 ;
            xy = "" ;
            continue ;
        }
        xy = xy + *(cpoints+i) ; 
        i++ ;
    }
    
    b2BodyDef ShapeBodyDef;
    ShapeBodyDef.type = b2_staticBody ;
    //ShapeBodyDef.
    //ShapeBodyDef.position.Set(fpointx/PTM_RATIO,fpointy/PTM_RATIO) ;
    
    b2Vec2 Position = b2Vec2(fpointx/PTM_RATIO*mapscale,fpointy/PTM_RATIO*mapscale);
    float32 Angle = -1 * CC_DEGREES_TO_RADIANS(spriteblock->getRotation());

    ShapeBodyDef.userData = spriteblock ;
    b2Body* ShapeBody = world->CreateBody(&ShapeBodyDef);
    ShapeBody->SetTransform(Position,Angle);

    //循环生成所有POLYLINE规则v1->v2,v2->v3...
    for(i = 0 ; i < num-1 ;i++)
    {
        Shape->Set(verts*,verts*) ;
        b2FixtureDef ShapeDef;
        ShapeDef.shape = Shape;
        ShapeDef.density = 10.0;
    
        //ShapeDef.
        ShapeDef.isSensor = false;
        ShapeBody->CreateFixture(&ShapeDef);
    }
    
}

}
**