C# ArgumentNullException:值不能为null,但它不是';T
我有一些Unity代码,用于从文件加载位图图像并将其添加到网格。但是我得到了一个C# ArgumentNullException:值不能为null,但它不是';T,c#,unity3d,C#,Unity3d,我有一些Unity代码,用于从文件加载位图图像并将其添加到网格。但是我得到了一个ArgumentNullException,我确信这个参数不是空的 无法加载图像的代码: Texture2D img=新的Texture2D(64,64); Debug.Log(“>>”+img+“错误是针对$”{Application.persistentDataPath}/textures/{sl}“不是img变量。请检查应用程序权限和文件路径。是否尝试加载其他映像?还是尝试设置映像?将文件.ReadAllByt
ArgumentNullException
,我确信这个参数不是空的
无法加载图像的代码:
Texture2D img=新的Texture2D(64,64);
Debug.Log(“>>”+img+“错误是针对$”{Application.persistentDataPath}/textures/{sl}“
不是img
变量。请检查应用程序权限和文件路径。是否尝试加载其他映像?还是尝试设置映像?将文件.ReadAllBytes
的返回值分配给变量,并检查它是否为null
。由于文件.ReadAllBytes($)无效,因此引发异常。”{Application.persistentDataPath}/textures/{sl}“
为空,而不是其他人指出的img
距离。请尝试加载其他文件或/并将其放入变量,以便您可以检查img.LoadImage
否之前,file.ReadAllBytes
是否为空。我打印了它的长度(12342)。为什么堆栈跟踪在LoadImage
中?我将File.ReadAllBytes($“{Application.persistentDataPath}/textures/{sl}”)
的返回值分配给一个名为bytes
的变量,并打印出长度,它表示12342,所以它不应该为空。
===============================================================
>> (UnityEngine.Texture2D)<<
UnityEngine.Debug:Log(Object)
Game:parseLine(String) (at Assets/Scripts/Game.cs:134)
Game:Awake() (at Assets/Scripts/Game.cs:78)
===============================================================
ArgumentNullException: Value cannot be null.
Parameter name: tex
UnityEngine.ImageConversion.LoadImage (UnityEngine.Texture2D tex, System.Byte[] data) (at /home/builduser/buildslave/unity/build/Modules/ImageConversion/ScriptBindings/ImageConversion.bindings.cs:35)
Game.parseLine (System.String line) (at Assets/Scripts/Game.cs:140)
Game.Awake () (at Assets/Scripts/Game.cs:78)ArgumentNullException: Value cannot be null.
===============================================================