【问题标题】:Xamarin Android KitKat Object reference not set to an instance of an objectXamarin Android KitKat 对象引用未设置为对象的实例
【发布时间】:2017-08-18 13:46:03
【问题描述】:

我刚刚在 VS2017 (15.3) 中安装了 Xamarin。

关注https://developer.xamarin.com/guides/android/platform_features/introduction_to_kitkat/https://developer.xamarin.com/guides/android/getting_started/hello,android/hello,android_quickstart/

项目文件的 Application android compile 版本设置为 Android 4.4 (Kit Kat)。 Android manifest min 和 target version 都设置为Android 4.4 (API Level 19 - Kit Kat)

对于调试器,我选择了

5" KitKat (4.4) XXHDPI Phone (Android 4.4 - API 19).

(7" 平板电脑也无法使用)。

当我构建/重建时,我得到:

1>------ Rebuild All started: Project: Phoneword, Configuration: Debug Any CPU ------
1>    Processing: obj\Debug\res\layout\main.xml
1>    Processing: obj\Debug\res\values\strings.xml
1>  Phoneword -> E:\Source\Workspaces\Phoneword\Phoneword\bin\Debug\Phoneword.dll
1>    Processing: obj\Debug\res\layout\main.xml
1>    Processing: obj\Debug\res\values\strings.xml
1>    Processing: obj\Debug\res\layout\main.xml
1>    Processing: obj\Debug\res\values\strings.xml
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

当我尝试调试时,我得到:“有部署错误。继续吗?”

1>----- 构建开始:项目:Phoneword,配置:调试任何 CPU ------

1>  Phoneword -> E:\Source\Workspaces\Phoneword\Phoneword\bin\Debug\Phoneword.dll
2>Starting deploy 5" KitKat (4.4) XXHDPI Phone ...
2>Starting emulator 5" KitKat (4.4) XXHDPI Phone ...
2>An error occured. See full exception on logs for more details.
2>Object reference not set to an instance of an object.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========

错误列表:

IDE0006 Error encountered while loading the project. Some project features, such as full solution analysis for the failed project and projects that depend on it, have been disabled.

在日志中(帮助 > Xamarin > 打开日志)我看到:

 System.NullReferenceException: Object reference not set to an instance of an object.
 at Microsoft.VisualStudio.Shell.ThreadHelper.get_JoinableTaskContext()
 at Microsoft.VisualStudio.Emulator.Utilities.VsTelemetryHelper.LogEvent(IServiceProvider serviceProvider, String eventPath, IDictionary`2 properties)
 at Microsoft.VisualStudio.Emulator.Logging.VsEmulatorTelemetryLogger.LogEvent(String eventName, IDictionary`2 properties)
 at Microsoft.VisualStudio.Emulator.Logging.DeviceTelemetryLogger.LogEvent(String eventName, IDictionary`2 properties)
 at Microsoft.VisualStudio.Emulator.EmulatorService.<>c__DisplayClass3_0.<StartAsync>b__0()
 at System.Threading.Tasks.Task`1.InnerInvoke()
 at System.Threading.Tasks.Task.Execute()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Xamarin.VisualStudio.Android.Devices.MicrosoftAndroidDeviceProvider.<>c__DisplayClass18_0.<<StartEmulator>b__0>d.MoveNext() in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio.Android\Devices\MicrosoftAndroidDeviceProvider.cs:line 114
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
 at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
 at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod, JoinableTaskCreationOptions creationOptions)
 at Merq.AsyncManager.Run[T](Func`1 asyncMethod) in C:\projects\merq\src\Async\Merq.Async.Core\Merq.Async.Core.Portable\AsyncManager.cs:line 64
 at Xamarin.VisualStudio.Android.Devices.MicrosoftAndroidDeviceProvider.StartEmulator(IAndroidVirtualDevice virtualDevice, IProgressReport progress, CancellationToken cancellationToken) in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio.Android\Devices\MicrosoftAndroidDeviceProvider.cs:line 114
 at Xamarin.VisualStudio.Android.CommandHandlers.StartupVirtualDeviceCommandHandler.StartUp(IMonoAndroidDevice device, IProgressReport progress, IAndroidVirtualDeviceProvider virtualDeviceProvider, CancellationToken cancellationToken) in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio.Android\CommandHandlers\StartupVirtualDeviceCommandHandler.cs:line 75
 at Xamarin.VisualStudio.Android.CommandHandlers.StartupVirtualDeviceCommandHandler.Execute(StartupVirtualDeviceCommand command, IProgressReport progress, CancellationToken cancellationToken) in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio.Android\CommandHandlers\StartupVirtualDeviceCommandHandler.cs:line 48
 at Xamarin.VisualStudio.Commands.CommandHandlerBase`2.Execute(TCommand command, CancellationToken cancellationToken) in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio\Commands\CommandHandlerBase.cs:line 151
 at Xamarin.VisualStudio.Commands.CommandHandlerBase`2.<>c__DisplayClass1_0.<ExecuteAsync>b__0() in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio\Commands\CommandHandlerBase.cs:line 117
 at System.Threading.Tasks.Task`1.InnerInvoke()
 at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---


 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Xamarin.VisualStudio.Android.CommandHandlers.DeployCommandHandler.<>c__DisplayClass19_0.<<StartUpVirtualDeviceAndDeploy>b__0>d.MoveNext() in C:\d\lanes\4985\306f76ac\source\xamarinvs\src\Core\VisualStudio.Android\CommandHandlers\DeployCommandHandler.cs:line 240

打开 Main.axml 时,我得到:

mono.android.DesignerException: java.lang.IllegalStateException
at mono.android.DesignerException.fromThrowable(DesignerException.java:46)
at mono.android.DesignerSession.checkRenderResultForError(DesignerSession.java:187)
at mono.android.DesignerSession.load(DesignerSession.java:239)
at mono.android.DesignerSession.processMessage(DesignerSession.java:704)
at mono.android.MessageListener.executeMessage(MessageListener.java:88)
at mono.android.MessageListener$Runner.run(MessageListener.java:44)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: The main Looper has already been prepared.
at android.os.Looper.prepareMainLooper(Looper.java:104)
at com.android.layoutlib.bridge.Bridge.prepareThread(Bridge.java:544)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368)
at mono.android.DesignerSession.load(DesignerSession.java:233)
... 4 more

有什么建议吗? Android SDK Manager 我已经安装了 Android SDK Build-tools 19.1 和 Android 4.4.2 (API 19)。

(19.1 因为 19.0.3 / 19.0.2 / 19.0.1 / 19 已过时)。

关于如何使它工作的任何建议?

(需要在安卓4.4.4的三星SM-T560上写一个应用)

【问题讨论】:

  • 我在另一台装有 vs2017 的机器上运行和构建的应用程序得到了相同的结果,但不是所有内容的最新版本(从 rc1 升级)这台笔记本电脑我擦除并安装了 2017.3从头开始,有这个问题。一旦我关闭 hyper V,Android 模拟器(非 -vs one)就可以正常工作,但对于一般调试来说太慢了。
  • 无法部署到模拟器。没有提供 -tsa 或 -tsacert 并且这个 jar 没有时间戳。如果没有时间戳,用户可能无法在签名者证书的到期日期 (2047-08-11) 或任何未来的撤销日期之后验证此 jar。 C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.3\zipalign.exe 4 "E:\Source\Workspaces\Phoneword\Phoneword\bin\Debug\Phoneword.Phoneword-Signed-Unaligned .apk" "bin\Debug\\Phoneword.Phoneword-Signed.apk" 完成构建项目 "Phoneword.csproj" -- 失败。

标签: c# android visual-studio xamarin.android


【解决方案1】:

我认为我已修复它 - 从开始菜单/应用程序列表中手动启动“Visual Studio 模拟器”,然后从 VS 模拟器工具中手动启动您想要的那个,这会启动并初始化它。下次我在 VS 中尝试它工作正常。您也可以使用模拟器 UI 下载其他配置文件和 API 级别,然后这些将作为选项显示在 VS2017 启动/调试下拉列表中。

【讨论】:

  • 如果我将“使用 Android 版本编译:”设置为 Android 5.0(棒棒糖)而不是 6.0(棉花糖)。我可以运行我的应用程序。不能让它在 kitkat 上运行,也不能让它在 marshmellow 上运行...... -_-
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多