null

AS3 -TypeError #1009 - any easy way to find out *which* object reference is null?

▼魔方 西西 提交于 2019-12-17 16:32:33
问题 We all get "TypeError #1009 Cannot access a property or method of a null object reference" now and then - no big deal, but sometimes frustrating to debug. Flash gives you the call stack (which is a start), but leaves it up to you to figure out where the null object is - is it possible to find out exactly which reference is throwing the error? Given the following (error prone) function: function nullObjectReferenceError():void { var obj:Object; var prop:* = obj.nonExistentProperty; } Rather

Why throwing exception in constructor results in a null reference?

回眸只為那壹抹淺笑 提交于 2019-12-17 16:14:53
问题 Why throwing exception in constructor results in a null reference? For example, if we run the codes below the value of teacher is null, while st.teacher is not (a Teacher object is created). Why? using System; namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { Test(); } private static void Test() { Teacher teacher = null; Student st = new Student(); try { teacher = new Teacher( "", st ); } catch ( Exception e ) { Console.WriteLine( e.Message ); } Console

Why type “int” is never equal to 'null'?

旧城冷巷雨未停 提交于 2019-12-17 16:13:56
问题 int n == 0; if (n == null) { Console.WriteLine("......"); } Is it true that the result of expression ( n == null ) is always false since a value of type int is never equal to null of type int? (see warning below) Warning CS0472 The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?' 回答1: If you want your integer variable to allow null values, declare it to be a nullable type: int? n = 0; Note the ? after int, which means that type can

How to check if String is null

試著忘記壹切 提交于 2019-12-17 16:00:41
问题 I am wondering if there is a special method/trick to check if a String object is null. I know about the String.IsNullOrEmpty method but I want to differentiate a null String from an empty String (= "" ). Should I simply use: if (s == null) { // blah blah... } ...or is there another way? 回答1: An object can't be null - the value of an expression can be null. It's worth making the difference clear in your mind. The value of s isn't an object - it's a reference , which is either null or refers to

PHP considers null is equal to zero

吃可爱长大的小学妹 提交于 2019-12-17 15:59:19
问题 In php, ($myvariable==0) When $myvariable is zero, the value of the expression is true; when $myvariable is null, the value of this expression is also true. How can I exclude the second case? I mean I want the expression to be true only when $myvariable is zero. Of course I can write ($myvariable!=null && $myvariable==0 ) but is there other elegant way to do this? 回答1: $myvariable === 0 read more about comparison operators. 回答2: You hint at a deep question: when should an expression be true?

Java: avoid checking for null in nested classes (Deep Null checking)

左心房为你撑大大i 提交于 2019-12-17 15:53:44
问题 Imagine I have a class Family. It contains a List of Person. Each (class) Person contains a (class) Address. Each (class) Address contains a (class) PostalCode. Any "intermediate" class can be null. So, is there a simple way to get to PostalCode without having to check for null in every step? i.e., is there a way to avoid the following daisy chaining code? I know there's not "native" Java solution, but was hoping if anyone knows of a library or something. (checked Commons & Guava and didn't

Querying MySQL with CodeIgniter, selecting rows where field is NULL

北战南征 提交于 2019-12-17 15:39:28
问题 I'm using CodeIgniter's Active Record class to query the MySQL database. I need to select the rows in a table where a field is not set to NULL: $this->db->where('archived !=', 'NULL'); $q = $this->db->get('projects'); That only returns this query: SELECT * FROM projects WHERE archived != 'NULL'; The archived field is a DATE field. Is there a better way to solve this? I know I can just write the query myself, but I wan't to stick with the Active Record throughout my code. 回答1: where('archived

Why do I get null instead of empty string when receiving POST request in from Razor View?

╄→гoц情女王★ 提交于 2019-12-17 15:25:11
问题 I used to receive empty string when there was no value: [HttpPost] public ActionResult Add(string text) { // text is "" when there's no value provided by user } But now I'm passing a model [HttpPost] public ActionResult Add(SomeModel Model) { // model.Text is null when there's no value provided by user } So I have to use the ?? "" operator. Why is this happening? 回答1: You can use the DisplayFormat attribute on the property of your model class: [DisplayFormat(ConvertEmptyStringToNull = false)]

Overriding == operator. How to compare to null? [duplicate]

烂漫一生 提交于 2019-12-17 15:14:38
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do I check for nulls in an ‘==’ operator overload without infinite recursion? There is probably an easy answer to this...but it seems to be eluding me. Here is a simplified example: public class Person { public string SocialSecurityNumber; public string FirstName; public string LastName; } Let's say that for this particular application, it is valid to say that if the social security numbers match, and both

error: ‘NULL’ was not declared in this scope

走远了吗. 提交于 2019-12-17 15:12:35
问题 I get this message when compiling C++ on gcc 4.3 error: ‘NULL’ was not declared in this scope It appears and disappears and I don't know why. Why? Thanks. 回答1: NULL is not a keyword. It's an identifier defined in some standard headers. You can include #include <cstddef> To have it in scope, including some other basics, like std::size_t . 回答2: GCC is taking steps towards C++11, which is probably why you now need to include cstddef in order to use the NULL constant. The preferred way in C++11