Optix throws error in the setAnyHitProgram method in material

In the optix sample,
optixmesh.cpp
method name - optix::Material createOptiXMaterial

mat->setAnyHitProgram(1u, any_hit ); this line throws the below error

“Invalid value (Details: Function “_rtMaterialSetAnyHitProgram” caught exception: Invalid ray type index: 1)”

can someone please help with this?

That would happen if there hasn’t been an rtContextSetRayTypeCount function call with a value of 2 or more before.
Please step through your code and see if there had been a sufficiently large raytype count set before that call.

OptiX API reference docs about those calls:
http://raytracing-docs.nvidia.com/optix/api/html/group___context.html#ga40880c075df428b0819270e340507943
http://raytracing-docs.nvidia.com/optix/api/html/group___material.html#ga0f0377c963b834ca84ff95ce4886b0c3