I am a high school student currently taking an introductory computer science course. In class we were assigned with creating a program that would take user input for card notation and return the full description of the card. For example, A user who inputs "AS" would see "Ace of Spades" in the terminal window. However, when my code executes, I get a "null of null" instead of "Ace of Spades" or another card notation.   public class Card  {  private String rank;   private String suit;  private String fullRank;  private String fullSuit;  public Card(String rankAndSuit) {     rank = rankAndSuit.substring(0,1);       if (rank == "A")     {            fullRank = "Ace";     }      else     if  (rank == "2")     {         fullRank = "2";      }     else     if (rank == "3")     {             fullRank = "3";     }      else     if  (rank == "4")     {          fullRank = "4";      }     else     if (rank == "5")     {             fullRank = "5";     }      else     if  (rank == "6")     {          fullRank = "6";      }     else     if (rank == "7")     {             fullRank = "7";     }      else     if  (rank == "8")     {         fullRank = "8";      }     else     if (rank == "9")     {             fullRank = "9";     }      else     if  (rank == "10")     {         fullRank = "10";      }     else     if (rank == "J")     {             fullRank = "Jack";     }      else     if  (rank == "Q")     {          fullRank = "Queen";      }     else     if (rank == "K")     {             fullRank = "King";     }        suit = rankAndSuit.substring(1,2);       if (suit == "D")     {            fullSuit = "Diamonds";     }      else     if  (suit == "H")     {         fullSuit = "Hearts";      }     else     if (suit == "S")     {             fullSuit = "Spades";     }      else     if  (suit == "C")     {      fullSuit = "Clubs";      } }  public String getCardDescription() {     return fullRank + " of " + fullSuit; }   }  My Tester Class is :  public class CardTester  {  public static void main(String[] args) {     Card testCard = new Card("AS");     String cardDescription = testCard.getCardDescription();      System.out.print(cardDescription); }   }  What is causing me to get null?
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
86556
I already looked at related questions, such as , but I am just as baffled as before. MWE:  \documentclass{article} \begin{document} \thepage\par \null\null\null\null\null\null\null\null \null\null\null\null\null\null\null\null \null\null\null\null\null\null\null\null \null\null\null\null\null\null\null\null \null\null\null\null\null\null\null\null \null\null\null\null\null\null \thepage\par \end{document}   The above code produces a two-page document. It prints \thepage as 1 on both pages. Add another \null or two, and the second \thepage correctly shows as 2.  Apparently, \thepage does not kick in until about the third line of the page. I have tried this with more complicated code, and it seems to be the general case.  Bug? Feature? My mistake? Is there any way I can get \thepage correct on the very first line of a page? OK to use LuaTeX.
124212
I'm using the MySQL Query Browser (part of the ) and need to change a field to NULL, but I can't figure out how to do it - if I delete the value it tries to update it to ''. Typing "NULL" makes it try to update to 'NULL' (a string).  I know I could just write a query to do it, but that defeats the entire purpose of the tool, no?
107801
I posted the code below to the Sun developers forum since I thought it was erroring (the true error was before this code was even hit).  One of the responses I got said it would not work and to throw it away.  But it is actually working.  It might not be the best code (I am new to Java) but is there something inherently "wrong" with it?   =============  CODE:   private static void ImportFromCsvToAccessTable(String mdbFilePath, String accessTableName  , String csvDirPath , String csvFileName ) throws ClassNotFoundException, SQLException {      Connection msConn = getDestinationConnection(mdbFilePath);     try{          String strSQL = "SELECT * INTO " + accessTableName + " FROM [Text;HDR=YES;DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";         PreparedStatement selectPrepSt = msConn.prepareStatement(strSQL );         boolean result = selectPrepSt.execute();                 System.out.println( "result = " + result );      } catch(Exception e) {         System.out.println(e);     } finally {         msConn.close();     } }
2771
Consider the following table:  id  title   genre1  genre2  genre3  genre4  genre5 1   Movie1  Thriller    Crime   NULL    NULL    NULL 2   Movie2  Fantasy NULL    NULL    NULL    NULL 3   Movie3  Political   Philosophical   Historical  NULL    NULL 4   Movie4  Science Fiction NULL    NULL    NULL    NULL   When I unpivot genre1, genre2, ... the NULL values are removed, so that, for example, the rows for Movie1 would be:  id title  genre     original_column 1  Movie1 Thriller  genre1 1  Movie1 Crime     genre2   Is there a way to include NULL values, for example:  id title  genre     original_column 1  Movie1 Thriller  genre1 1  Movie1 Crime     genre2 1  Movie1 NULL      genre3 1  Movie1 NULL      genre4 1  Movie1 NULL      genre5   I can SELECT ISNULL(genre1, '*'), ISNULL(genre2, '*') ..., but suppose I want the values to appear as NULL? Is there a better way than:  WITH  -- SELECT that unpivots table AS unpivoted SELECT unpivoted.id,    unpivoted.title,    ,CASE unpivoted.genre WHEN '*' THEN NULL ELSE unpivoted.genre END    ,unpivoted.original_transaction FROM unpivoted   Also, I notice that the query that returns the source data to be unpivoted MUST have an alias. For example:  SELECT ... FROM   -- *must* give it an alias or it's a syntax error   (SELECT ... FROM) AS source    UNPIVOT(genre for original_column IN (genre1,genre2, genre3,genre4,genre5))   Does anyone know why? I have not found a way to refer to the alias anywhere in the query.
90464
We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.  Is there a reason why "null" has even been included in the language?  After all, if there were no "null", I would have no bug, right?  In other words, what feature in the language couldn't work without null?
12375
I have a simple setter method for a property and null is not appropriate for this particular property. I have always been torn in this situation: should I throw an , or a ? From the javadocs, both seem appropriate. Is there some kind of an understood standard?  Or is this just one of those things that you should do whatever you prefer and both are really correct?
38323
This code compiles but in preview, it shows an error Invalid selectOptions found. Use SelectOption type in Apex.   public list&lt;student__c&gt; myStud = new list&lt;student__c&gt;();    List&lt;student__c&gt; stud_qry = new List&lt;student__c&gt;();     public list&lt;student__c&gt; getStud(){         stud_qry =  [select Id, First_Name__c, name from Student__c];          for(student__c getEm : stud_qry){           myStud.add(new student__c(Name = getEm.first_name__c+' ' + getEm.name));            }            return myStud;    }   VFP  &lt;apex:outputText &gt;Select Student:&lt;/apex:outputText&gt;                 &lt;apex:selectList size="1"&gt;                      &lt;apex:selectOptions value="{!Stud}"/&gt;                 &lt;/apex:selectList&gt;
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
41403
Seeing that /dev/null's utility isn't immediately obvious to me, what is the use of /dev/null piping?
23661
Context Around this Code: I am making a schedulable class run each Sunday to track a couple of metrics important to the team.   Question: I am looking to consolidate DML operations and a big part of this is understanding pass by reference vs pass by value.  I want to pass the salesOps user object to the method SDREfficiencyLastWeek. I made the return type void, because I figured that I will be passing this by reference and I can make all the updates in the method without having to anything.   Why I am confused:    I read the above article and am thrown off by the following statement:  "Non-primitive data type arguments, such as sObjects, are also passed into methods by value. "   If the object is indeed passed by reference, then the query for the salesOps user in my code should be sufficient enough to edit all fields on that object without actually having to state each field in the query.  global class SDREfficientMetricsSchedulable implements Schedulable  {     global void execute(SchedulableContext sc)      {         User salesOps = [SELECT ID FROM USER WHERE id = '0056A000002Z3p9QAC'];         List&lt;String&gt; queries = new List&lt;String&gt;();          String contactsWorked_lastWeek  = 'select count(id) results from contact where LastActivityDate = last_week';         queries.add(contactsWorked_lastWeek);          String demosSet_lastWeek            = 'select count(id) results from form__c where CreatedDate = last_week';         queries.add(demosSet_lastWeek);          String demosCompleted_lastWeek  = 'select count(id) results from opportunity where (stagename = \'Unqualified Demo Completed\'  OR stagename = \'Qualified Demo Completed\' )  and RecordTypeId = \'0126A000000yudDQAQ\' and CloseDate = last_week';         queries.add(demosCompleted_lastWeek);          String qualifiedDemos_lastWeek  = 'select count(id) results  from opportunity where RecordTypeId = \'0126A0000004Ao6QAE\' and isclosed = false and  SDR_Owner__c != null and CreatedDate = last_week';         queries.add(qualifiedDemos_lastWeek);          String closedWon_lastWeek       = 'select count(id) results  from opportunity where RecordTypeId = \'0126A0000004Ao6QAE\' and iswon = true and  SDR_Owner__c != null and CloseDate = last_week';         queries.add(qualifiedDemos_lastWeek);            SDREfficiencyLastWeek(queries, salesOps);          update salesOps;     }       public void SDREfficiencyLastWeek(List&lt;String&gt; queries, User salesOps )     {        }  }
34471
What is wrong in the below trigger syntax, I am getting this error An unexpected token "INT" was found following " DECLARE NULL_ROW_ID".  Expected tokens may include:  "END-OF-STATEMENT".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.68.61  CREATE TABLE A (     A_ID INT NOT NUll,     A_CODE VARCHAR(100) NOT NULL,     PRIMARY KEY(A_ID) );  CREATE TABLE B (     B_ID INT NOT NUll,     B_CODE VARCHAR(100) NOT NULL,     A_ID INT,     PRIMARY KEY (B_ID),     FOREIGN KEY (A_ID) REFERENCES A (A_ID)  );  CREATE OR REPLACE TRIGGER B_TRIGGER AFTER UPDATE OF A_ID ON B REFERENCING NEW AS N OLD AS O FOR EACH ROW     WHEN (N.A_ID IS NULL)     BEGIN ATOMIC         DECLARE NULL_ROW_ID INT;         SET NULL_ROW_ID = (SELECT A_ID FROM A WHERE A_CODE = 'Custom Null String');         IF NULL_ROW_ID IS NULL THEN             SIGNAL SQLSTATE '70000' SET MESSAGE_TEXT = 'Custom Null String row not found.';         END IF;     SET N.A_ID = NULL_ROW_ID;     END @   It's on DB2 Express-C 10.5
65166
It seems like my code works to check for null if I do  if ($tx)    or   if (isset($tx))   why would I do the second one when it's harder to write?
12823
In .NET, what is the difference between String.Empty and "", and are they interchangable, or is there some underlying reference or Localization issues around equality that String.Empty will ensure are not a problem?
97720
I'm using the following python code to replace Null values by 0, using field calculator:  def nulls(p1):  if p1 is None:     return 0  else:     return p1   But nothing happens, Null values stay. I'm using ArcGIS Desktop 10.0.
63419
I'm working with ArcGIS 10.2 for Desktop and OS Windows 7.   I need to set numeric vales from Zero back to NULL, but I can't from the field calculator.  I'm working with  a vector file and I need to display NULL in one column that shows 0 (Zero) as default value.  -------- Edit------- I am adding the error messages that he received  Translation:  An error occurred during the process.  Please consult the Geoprocessing Results Window to obtain more details.  Error at bottom, translation:  The values ​​of the selected column can not be set to null because the field in the database is defined as "Not Null".
107240
Quite often, in programming we get situations where null checks show up in particularly large numbers. I'm talking about things like:  if (doc != null) {   if (doc.Element != null)   {     ... and so on   }   else     throw new Exception("Element cannot be null"); } else {   throw new Exception("document cannot be null"); }   Basically, the whole thing turns into an unreadable nightmare, so I'm wondering: is there an easier way to describe what I'm trying to do above? (In addition to null checks, I get things like string.IsNullOrEmpty from time to time.)  Accepted answer: I accepted the answer that has  because the approach described is innovative, and is precisely what I want. Thanks Shawn!