Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ArgumentNullException:值不能为null,但它不是';T_C#_Unity3d - Fatal编程技术网

C# ArgumentNullException:值不能为null,但它不是';T

C# ArgumentNullException:值不能为null,但它不是';T,c#,unity3d,C#,Unity3d,我有一些Unity代码,用于从文件加载位图图像并将其添加到网格。但是我得到了一个ArgumentNullException,我确信这个参数不是空的 无法加载图像的代码: Texture2D img=新的Texture2D(64,64); Debug.Log(“>>”+img+“错误是针对$”{Application.persistentDataPath}/textures/{sl}“不是img变量。请检查应用程序权限和文件路径。是否尝试加载其他映像?还是尝试设置映像?将文件.ReadAllByt

我有一些Unity代码,用于从文件加载位图图像并将其添加到网格。但是我得到了一个
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.
===============================================================