這是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中創建了哪些項目類型?基本上沒有足夠的信息來幫助你... –