我正在开发使用Parse Android SDK的应用程序。应用程序在调试模式下正常工作但是当我在发布模式下编译时,我得到以下错误。执行解析查询时发生错误。不是我初始化解析时。
[MonoDroid] UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
[MonoDroid] at Parse.PlatformHooks+<RequestAsync>d__19.MoveNext () [0x00000] in <filename unknown>:0
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[MonoDroid] at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0
[MonoDroid] at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0
[MonoDroid] at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0
[MonoDroid] at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[MonoDroid] at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Collections.Generic.IEnumerable`1[Parse.ParseObject]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0
[MonoDroid] at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`1[Parse.ParseObject]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0
[MonoDroid] at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0
[MonoDroid] at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[MonoDroid] at System.Runtime.CompilerServices.TaskAwaiter`1[System.Collections.Generic.IEnumerable`1[Parse.ParseObject]].GetResult () [0x00000] in <filename unknown>:0
[MonoDroid] at ParseDAL.ParseCaller+<Init>c__async0.MoveNext () [0x00000] in <filename unknown>:0
[mono]
[mono] Unhandled Exception:
[mono] System.NullReferenceException: Object reference not set to an instance of an object
[mono] at Parse.PlatformHooks+<RequestAsync>d__19.MoveNext () [0x00000] in <filename unknown>:0
[mono] --- End of stack trace from previous location where exception was thrown ---
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[mono] at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0
[mono] at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0
[mono] at System.Threading.Tasks.Task.InnerInvoke
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
[mono-rt] at Parse.PlatformHooks+<RequestAsync>d__19.MoveNext () [0x00000] in <filename unknown>:0
[mono-rt] --- End of stack trace from previous location where exception was thrown ---
[mono-rt] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
[mono-rt] at Parse.Internal.InternalExtensions+<>c__DisplayClass7`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]].<OnSuccess>b__6 (System.Threading.Tasks.Task t) [0x00000] in <filename unknown>:0
[mono-rt] at System.Threading.Tasks.TaskActionInvoker+FuncTaskInvoke`1[System.Threading.Tasks.Task`1[System.Tuple`2[System.Net.HttpStatusCode,System.Collections.Generic.IDictionary`2[System.String,System.Object]]]].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0
[mono-rt] at System.Threading.Tasks.Task
以下是代码:
ParseClient.Initialize("App Id", "Dot Net Key");
var userQuery = ParseObject.GetQuery ("Table Name");
var userData = await userQuery.FindAsync ();
foreach (var ud in userData) {
Console.WriteLine ("UD " + ud.Get<string>(Constants.COL_USER_NAME));
}
我尝试了所有链接器选项“Dont Link”,“Link All Assemblies”,“Link SDK assemblies”。但是app仍在崩溃。
答案 0 :(得分:14)
发生此异常是因为网络问题不是因为调试/发布版本。在调试模式下,INTERNET权限会自动添加到清单文件中,但不会在发布模式下添加。 因此,请在清单文件中添加此权限。
<uses-permission android:name="android.permission.INTERNET" />
在发布模式下不会发生此异常。
在发送解析请求之前,我们仍然需要检查网络是否可用。