这是cs文件中单运行良好:我该如何解决这个ArgumentNullException?
using System;
public class HelloWorld
{
static public void Main()
{
Console.WriteLine("Enter a number");
int UserNumber = int.Parse(Console.ReadLine());
Console.WriteLine("Your number is: " + UserNumber);
}
}
我开了Xamarin这个test.cs中的文件,它工作正常。那么,我选择“运行”>“开始不调试”和这些错误的显示面板弹出:
Enter a number
Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: String
at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number, System.Globalization.NumberFormatInfo info, Boolean parseDecimal) [0x00054] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:1084
at System.Number.ParseInt32 (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:755
at System.Int32.Parse (System.String s) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/int32.cs:140
at HelloWorld.Main() [0x0000b] in /Users/Yardenbourg/Desktop/Test.cs:9
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Argument cannot be null.
Parameter name: String
at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number, System.Globalization.NumberFormatInfo info, Boolean parseDecimal) [0x00054] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:1084
at System.Number.ParseInt32 (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:755
at System.Int32.Parse (System.String s) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/int32.cs:140
at HelloWorld.Main() [0x0000b] in /Users/Yardenbourg/Desktop/Test.cs:9
The application was terminated by a signal: SIGHUP
我不知道这里的问题是什么。这可能与这条线有关吗?
int UserNumber = int.Parse(Console.ReadLine());
使这个问题具体。例如。有一条声明读为:如果我们知道错误是什么,那么我们可以提供帮助。 – Richard
“只要我尝试将ReadLine或if/else放在那里,它就会出现一堆错误,并且不会编译。”什么错误?您在Xamarin Studio中创建了哪些项目类型?基本上没有足够的信息来帮助你... –