- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在涉足 Android 的 MonoTouch/Mono,目前正在创建我自己的 UIColor 子类。不知何故,我无法让我的工厂方法以我想要的方式工作(但我确实有一个解决方法)。
以下代码导致我崩溃:
using System;
#if ANDROID
// TODO: T.B.I.
#else
using MonoTouch.UIKit;
#endif
namespace OurCompany.Core
{
public class Color : UIColor
{
public Color (float r, float g, float b, float a) : base(r, g, b, a)
{
}
// our webservice sends color strings in the following ugly format:
// 0,255,100,1.0
public static Color FromColorString (string colorString)
{
var comps = colorString != null ? colorString.Split (new char[] {','}) : null;
if (comps == null || comps.Length != 4) {
return null;
}
float r = 0.0f, g = 0.0f, b = 0.0f, a = 1.0f;
float.TryParse (comps [0], out r);
float.TryParse (comps [1], out g);
float.TryParse (comps [2], out b);
float.TryParse (comps [3], out a);
return new Color (r, g, b, a);
}
}
}
return (Color)UIColor.FromRGBA (
r > 0 ? r / 255 : 0.0f,
g > 0 ? g / 255 : 0.0f,
b > 0 ? b / 255 : 0.0f,
a
);
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr) <IL 0x00026, 0xffffffff>
at MonoTouch.UIKit.UIColor.get_CGColor () [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIColor.g.cs:476
at MonoTouch.UIKit.UIColor.GetRGBA (single&,single&,single&,single&) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIColor.cs:51
at MonoTouch.UIKit.UIColor.ToString () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIColor.cs:141
at string.FormatHelper (System.Text.StringBuilder,System.IFormatProvider,string,object[]) [0x00168] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1890
at string.Format (System.IFormatProvider,string,object[]) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1820
at string.Format (string,object[]) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1815
at OurCompany.Core.AppDefaults.ToString () [0x00000] in /Volumes/Development/Mono/OurCompany/OurCompany.Core.Cloned/DL/AppDefaults.cs:78
at string.FormatHelper (System.Text.StringBuilder,System.IFormatProvider,string,object[]) [0x00168] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1890
at string.Format (System.IFormatProvider,string,object[]) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1820
at string.Format (string,object) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1800
at System.IO.TextWriter.Write (string,object) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.IO/TextWriter.cs:191
at System.IO.TextWriter.WriteLine (string,object) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.IO/TextWriter.cs:305
at System.IO.SynchronizedWriter.WriteLine (string,object) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.IO/TextWriter.cs:598
at System.Console.WriteLine (string,object) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Console.cs:459
at OurCompany.Core.AppDefaults..ctor (System.IO.MemoryStream) [0x0012b] in /Volumes/Development/Mono/OurCompany/OurCompany.Core.Cloned/DL/AppDefaults.cs:73
at OurCompany.Core.HomeScreenService/<LoadAppDefaultsAsync>c__AnonStorey2.<>m__2 (byte[],System.Exception) [0x0000f] in /Volumes/Development/Mono/OurCompany/OurCompany.Core.Cloned/SAL/HomeScreenService.cs:47
at OurCompany.Core.ServiceRequest/<LoadRequestAsync>c__AnonStorey4.<>m__4 (object,System.Net.DownloadDataCompletedEventArgs) [0x00022] in /Volumes/Development/Mono/OurCompany/OurCompany.Core.Cloned/SAL/ServiceRequest.cs:31
at System.Net.WebClient.OnDownloadDataCompleted (System.Net.DownloadDataCompletedEventArgs) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebClient.cs:1388
at System.Net.WebClient.<DownloadDataAsync>m__D (object) [0x00019] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebClient.cs:1037
at System.Threading.Thread.StartInternal () [0x00032] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs:699
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x0004e, 0xffffffff>
0 OurCompanyiOS 0x0009148c mono_handle_native_sigsegv + 284
1 OurCompanyiOS 0x00005568 mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x99d7686b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 CoreFoundation 0x012c3ae0 __CFStringAppendFormatCore + 16208
5 CoreFoundation 0x012bfaab CFStringCreateWithFormatAndArguments + 107
6 CoreFoundation 0x01348da1 +[NSException raise:format:] + 65
7 UIKit 0x028f7f34 -[UIColor CGColor] + 82
8 ??? 0x100a2743 0x0 + 269100867
9 ??? 0x140ee158 0x0 + 336519512
10 ??? 0x140edcbc 0x0 + 336518332
11 ??? 0x140eda18 0x0 + 336517656
12 ??? 0x0fbf703a 0x0 + 264204346
13 ??? 0x13e03a8c 0x0 + 333462156
14 ??? 0x140e9394 0x0 + 336499604
15 ??? 0x140e90c8 0x0 + 336498888
16 ??? 0x0fbf703a 0x0 + 264204346
17 ??? 0x13e03a8c 0x0 + 333462156
18 ??? 0x13ecd1b0 0x0 + 334287280
19 ??? 0x13ecd110 0x0 + 334287120
20 ??? 0x13ecd0a7 0x0 + 334287015
21 ??? 0x13eccffe 0x0 + 334286846
22 ??? 0x13eccf68 0x0 + 334286696
23 ??? 0x13ebb838 0x0 + 334215224
24 ??? 0x13ebb0c8 0x0 + 334213320
25 ??? 0x13ea481a 0x0 + 334120986
26 ??? 0x13ea42e9 0x0 + 334119657
27 ??? 0x13e167f2 0x0 + 333539314
28 ??? 0x13e150d7 0x0 + 333533399
29 ??? 0x0fbf4070 0x0 + 264192112
30 OurCompanyiOS 0x00009922 mono_jit_runtime_invoke + 722
31 OurCompanyiOS 0x0016c4ae mono_runtime_invoke + 126
32 OurCompanyiOS 0x0016c61c mono_runtime_delegate_invoke + 140
33 OurCompanyiOS 0x001a7522 start_wrapper + 466
34 OurCompanyiOS 0x001d94ba thread_start_routine + 154
35 OurCompanyiOS 0x002008ad GC_start_routine + 93
36 libsystem_c.dylib 0x99d8a557 _pthread_start + 344
37 libsystem_c.dylib 0x99d74cee thread_start + 34
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
最佳答案
好吧,我意识到我做错了什么,我应该更清楚地检查错误信息。
我的 AppDefaults 类具有以下 ToString() 方法(由 MonoDevelop 自动完成,并且可能仍然依赖于我之前的 UIColor
实现):
public override string ToString ()
{
return string.Format ("[AppDefaults: name={0}, appId={1}, userId={2}, themeId={3}, parallaxEnabled={4}, themeModifyDate={5}, tabBarColor={6}, tabColor={7}, backButtonColor={8}]", name, appId, userId, themeId, parallaxEnabled, themeModifyDate, tabBarColor, tabColor, backButtonColor);
}
at MonoTouch.UIKit.UIColor.GetRGBA (single&,single&,single&,single&) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIColor.cs:51
at MonoTouch.UIKit.UIColor.ToString () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIColor.cs:141
at string.FormatHelper (System.Text.StringBuilder,System.IFormatProvider,string,object[]) [0x00168] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/String.cs:1890
ToString()
类中的方法。我讨厌我在这个明显的错误上浪费了 6 个小时,但是在使用新框架时总是会发生这样的事情......
ToString()
我的自定义 Color 子类中的方法,尽管这本身似乎并不能防止崩溃。我确实意识到,如果某个随机的人会使用此代码,我需要防止将来发生这种崩溃。
null
值(0x000 ....)。调用 GetRGBA() 时出现问题。也许我需要覆盖
UIColor
的一些成员使此方法起作用的基类?我可以想象
GetRGBA()
正在调用我的自定义
Color
类而不是
UIColor
基类,导致失败。
关于c# - UIColor 子类中的工厂方法导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14865179/
我应该执行以下操作: 可能通过服务/工厂,使用 $q(异步)查询 API 以获取大型名称数据集 有另一个服务(也是异步的),它应该只返回上述工厂的元素,如果它们与某个字符串(搜索字段)匹配。目的是缩小
我有一个通用的基类。我有一个实现基类的具体类。 我将如何创建工厂类/方法来交付不同类型的具体类? 举个例子: public class ReceiverBase where T : IInte
我正在查看以下链接中的 Ninject Factory 扩展: http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-intro
工厂、提供商和服务这三个术语之间有什么区别? 刚刚了解 NHibernate 及其存储库模式(POCO 类等)。 最佳答案 工厂:通过将一堆位组合在一起或基于某种上下文选择类型来组装类 Provide
使用CGLIB我可以做到 final var enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setSuperclas
我试图在 Kotlin 中使用伴随对象工厂方法(相当于 Java 中的静态工厂方法)创建一个嵌套内部类。这是我的代码的简化版本。 class OuterClass { var myData:L
我正在为我的大学做一个项目,但遇到了问题。 基本上,该项目由一个客户端-服务器应用程序组成,我想创建一个用于通信的 Packet 类。数据包由 header 和主体组成。现在问题来了。我可以有一些不同
这个问题在这里已经有了答案: Why doesn't polymorphism work without pointers/references? (6 个答案) What is object sl
我正在制作一个套接字工厂。我希望每个外部应用程序都使用 Socket 类的接口(interface),它是几个类(ServerSocketTCP、ClientSocketTCP、ServerSocke
我是 angularjs 的新手,我正在尝试创建一个小型电影数据库。这是我第一次使用工厂,我想确保这是正确的方法,以及如何在另一个功能中使用这个工厂,如下所示? 我希望这个工厂只运行一次,这样我就可以
这个问题在这里已经有了答案: Java inner class and static nested class (28 个答案) 关闭 5 年前。 public class DataFactory
我看过很多关于 C++ 工厂的帖子,但到目前为止我还没有看到解决我的问题的解决方案。 (虽然我可能遗漏了一些东西。) 示例控制台应用程序: #include #include #include
这是一个简单的 C++ 项目,有 2 种设计模式:单例和工厂,sigleton 也是一个模板化类,一个接口(interface) (IHash) 和一个类 (Hash1)。一个简单的工厂类 (Hash
这个问题类似于Factory and generics ,并且可能有相同的答案,但它是不同的。我有一个通用基类,它将由完全独立的 JAR 中的类进行扩展。所述 JAR 应该能够在不更改任何其他代码的情
问题是我需要为传递的类创建一个新实例 有没有办法重写这个函数,让它可以接受任意数量的参数? function createInstance(ofClass, arg1, arg2, arg3, ...
我想用简单的 C++ 语法创建一个简单的工厂方法: void *createObject(const char *str,...) { if(!strcmp("X",str)) retu
经过大约 10 个月的程序化 PHP 学习后,我现在正尝试着手研究基本的 OOP 原则和设计模式。这是一个爱好,我没有那么多时间去追求它,所以请原谅这个问题的水平很低。 我的网站(目前 100% 程序
我有一个简单的问题。 我如何编写一个工厂来定义使用 make() 或 create() 的关系,具体取决于原始调用 make() 还是 create()? 这是我的用例: 我有一个简单的工厂 /**
我正在尝试在延迟加载模块中提供 APP_BASE_HREF 注入(inject) token ,然而,工厂方法根本没有被调用。 在这里https://github.com/MaurizioCascia
我有以下 ast: import { factory as f } from 'typescript' const typeDeclaration = f.createTypeAliasDeclara
我是一名优秀的程序员,十分优秀!