I need advice on how I can avoid java.lang.NullPointerException when dealing with JDBC result set which I put on Swing components such as JTable  I have written a method which gets the result set encapsulated in an object from a DAO Implementation which I populate inside a DefaultTableModel.  The problems is, the object returned by the dao implementation service may or may not have data/result set if the database table has no record yet.  This results to a NullPointerException  public DefaultTableModel getMiscellaneous(int gradeLevelId){         DefaultTableModel defaultTableModel = new DefaultTableModel();         String[] columns = {"Name","Amount"};         MiscellaneousFees miscellaneousFees =  schoolFeesDaoImpl.getMiscellaneous(gradeLevelId);         List&lt;Fee&gt; feeList = miscellaneousFees.getFees();         for(Fee fee: feeList){             Object[] rowData = {fee.getName(),fee.getAmount()};             defaultTableModel.addRow(rowData);         }         defaultTableModel.setColumnIdentifiers(columns);         return defaultTableModel;     }  public MiscellaneousFees getMiscellaneous(int gradeLevelId) {         MiscellaneousFees miscellaneousFees = new MiscellaneousFees();         List&lt;Fee&gt; feeList = new ArrayList&lt;&gt;();          String SQL = "{CALL getMiscellaneousFeesByGradeLevelId(?)}";         try (Connection con = DBUtil.getConnection(DBType.MYSQL);                 CallableStatement cs = con.prepareCall(SQL);){             cs.setInt(1, gradeLevelId);             try(ResultSet rs = cs.executeQuery();){                 while(rs.next()){                     SchoolYear schoolYear = new SchoolYear();                     schoolYear.setSchoolYearId(rs.getInt("schoolyear_id"));                     schoolYear.setYearFrom(rs.getInt("yearFrom"));                     schoolYear.setYearTo(rs.getInt("yearTo"));                     schoolYear.setIsActive(rs.getBoolean("isActive"));                     schoolYear.setStart_date(rs.getDate("start_date"));                     schoolYear.setEnd_date(rs.getDate("end_date"));                     schoolYear.setIsCurrentSchoolYear(rs.getBoolean("isCurrentSchoolYear"));                      GradeLevel gradeLevel = new GradeLevel();                     gradeLevel.setId(rs.getInt("gradelevel_id"));                     gradeLevel.setLevel(rs.getInt("grade_level"));                     gradeLevel.setIsActive(rs.getBoolean("isActive"));                      FeeCategory feeCategory = new FeeCategory();                     feeCategory.setCategory(rs.getString("fee_category"));                     feeCategory.setId(rs.getInt("fee_category_id"));                      Fee fee = new Fee();                     fee.setId(rs.getInt("fee_id"));                     fee.setName(rs.getString("fee_name"));                     fee.setDescription(rs.getString("fee_description"));                     fee.setAmount(rs.getDouble("fee_amount"));                     fee.setFeeCategory(feeCategory);                     fee.setGradeLevel(gradeLevel);                     fee.setSchoolYear(schoolYear);                     feeList.add(fee);                 }                 miscellaneousFees.setFees(feeList);             }         } catch (SQLException e) {             JOptionPane.showMessageDialog(null,e.getMessage());         }         return miscellaneousFees;     }   Any suggestion or advice of how I can prevent the NullPointerException when result set contained in the miscellaneous object is empty?  I get the NullPointerException error in this line of code   MiscellaneousFees miscellaneousFees =  schoolFeesDaoImpl.getMiscellaneous(gradeLevelId);   Thank you.
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
A world where nothing can be hidden. No lies, always truth In a Bollywood movie Pk, a man comes from a planet where lying is not possible as all the thoughts/knowledge is transferable via human contact. Due to which they do not have to lie about anything or hide anything from each other.  Say, such a society plausible with technology, if we decide to abandon the privacy as we know today. All the recorded data (written, spoken, recorded videos etc.) and thought (via neuralink) is accessible to everyone, everywhere.  Basic idea behind the question is, people worry about data being accumulated at one place (entity or government) and being used against them or to deceive them. If everything is accessible/known to everyone of about anyone and anything, what does privacy mean in this case? Is there a word in English to qualify the highest-ranked student in a class in a year?  We are talking here about higher education, especially in the context of curricula that keep a given set of students over the course of several years, being ranked at the end of each year, possibly with competitive admission for the following year. The ranking is a weighted average of all marks obtained over the year.  I am looking for a single word, or expression, to quickly designate the one student with the highest ranking. If there is no such thing in English, then let's try to get the most concise and idiomatic definition.  In all cases, it is not emotionally connoted, i.e. not pejorative nor bragging.  For French speakers: I am looking for the translation of “major de promotion”.    EDIT: additional, not as much of a pure “word request” question: is this anything you should mention on a curriculum vitæ in the English-speaking world? If so, please mention whether the given word is appropriate for such a use&nbsp;&nbsp;:) Find the condition on $a$ and $b$ so that the two tangents drawn to the parabola $y^2=4ax$ from a point are normals to the parabola $x^2=4by$ Find the condition on $a$ and $b$ so that the two tangents drawn to the parabola $y^2=4ax$ from a point are normals to the parabola $x^2=4by.$  The required condition is $a^2&gt;8b^2$.I dont know how to prove it.I tried.  Let $(h,k)$ be the point from where tangents are drawn to the parabola $y^2=4ax$.Let $m_1,m_2$ be the slopes of the tangents.Equations of tangents are $y=m_1x+\frac{a}{m_1}$ and $y=m_2x+\frac{a}{m_2}$ and equations of normal to the parabola $x^2=4by$ is $y=m_1x-2bm_1-bm^3_1$ and $y=m_2x-2bm_2-bm^3_2$.  As $y=m_1x+\frac{a}{m_1}$ and $y=m_1x-2bm_1-bm^3_1$  are the same lines.Therefore,$\frac{a}{m_1}=-2bm_1-bm^3_1$  $bm^4+2bm^2+a=0$  And I am stuck.I cannot get the desired condition.Please help me. I am travelling to Athens, Greece, shortly, and have seen . Should I be worried? Should I cancel my trip?  Update  It's fine, taxis are currently on strike, but Syntagma Sqaure is fine: Is there an advantage to use a Synchronized Method instead of a Synchronized Block? I heard that there was a twitter bot which automatically posted questions and asked for answers for specific questions on every site. How do they work? Is there an algorithm for doing this or is it purely random? I know that it doesn't tweet closed questions, but that's it. Structure of a C++ Object in Memory Vs a Struct If I have a class as follows     class Example_Class     {        private:          int x;           int y;         public:           Example_Class()           {               x = 8;              y = 9;          }        ~Example_Class()         { }     };   And a struct as follows  struct {    int x;    int y; } example_struct;   Is the structure in memory of the  example_struct simmilar to that in Example_Class  for example if I do the following  struct example_struct foo_struct; Example_Class foo_class = Example_Class();  memcpy(&amp;foo_struct, &amp;foo_class, sizeof(foo_struct));   will foo_struct.x = 8 and foo_struct.y = 9 (ie: the same values as the x,y values in the foo_class) ?  The reason I ask is I have a C++ library (don't want to change it) that is sharing an object with C code and I want to use a struct to represent the object coming from the C++ library. I'm only interested in the attributes of the object.  I know the ideal situation would be to have Example_class wrap arround a common structure between the C and C++ code but it is not going to be easy to change the C++ library in use. Is Stack Overflow merging two different accounts by email without the user's consent? I had one account through Google with email X and another account through myopenid.com. I happened to add the same email X to this myopenid.com account. My intention was to stop using the Google account in favor of the new myopenid.com account.   After some time asking and answering questions with my openid.com account I am astonished to find out that it is now merged into my Google account. That creates all kinds of privacy issues. I thought the email on my Stack Overflow account was private. Did I miss anything here?  To be clear, I wanted to preserve my privacy in the second account, but now since all my recent questions were transferred to the old account, my privacy is completely lost.  And it looks like there is no verification for the email field in my profile, so if Stack Overflow is using that info to merge, there is a very serious security bug. If it is merging based on something else, that's even worse. I think your account belongs to that user here. Let me merge it. Terrible! Gparted: move extended partition on the left I have some free disk space on the left of my ubuntu (sda5)  What is best solution to extend sda5 ?  I can    copy sda3 or sda5 with dd to bigger disk. delete sda3,5,swap create sda3,5,swap dd original partition.   Not sure how to do it properly.  May be there is a simpler solution. Do descriptive statistics have p-values? Dimensions of Scale (Gamma) and Offset (Beta) in Batch Norm While implementing Batch Normalization for a particular layer 'L' with 'n' hidden neurons/units in a Neural Network, we first normalize the Activation values of that layer using their respective Mean and Standard Deviation, and then apply the Scaling and Offset factor as shown:     X-norm = (X - mu)/sd X' = (Y * X-norm) + B       where    mu = mean of X and it is a (n,1) vector          sd = standard deviation of X and it is also a (n,1) vector         X = Activation values of layer 'L' with dimension (n,m) if mini-batch    size = m   X-norm = normalized X with dimension (n,m)   Y = Gamma / Scaling factor   B = Beta / Offset factor   Now my question is, what are the dimensions of Gamma and Beta ? Are they (n,1) vectors or are they (n,m) matrices ? My intuition says that since they somewhat are analogous to the Mean and Standard Deviation, they should be (n,1) vectors. I know a lot of female programmers, and I know there are a good number of them out there.  But I don't recall ever having one of my questions answered by, nor have I ever answered a question by a female programmer here at Stack&nbsp;Overflow.  Now I mostly deal in the Delphi tag, and that may make a difference. But I've got the feeling there is something about the programming social network that Stack&nbsp;Overflow is, along with its form of mini-competition (via reputation) that turns most ladies off.  When I go down the first few pages of top users by rep, there is nary a lady to be found.  Go over to Quantcast and . Go down to the Demographics, and you'll see that a full 20% of the visits are by females. So they are here, lurking and using the wonderful info that Stack&nbsp;Overflow provides.  Then why aren't there more of them participating, both with questions and answers?  What can Stack&nbsp;Overflow do to persuade female programmers to participate more?    So after a dozen downvotes offset by a dozen upvotes, and accusations by many that I am a bigot, the bottom line seems to be that Stack&nbsp;Overflow appeals to males more than females.  This is my observation and I believe a proper analysis would support the hypotheses that a much higher percentage of male programmers use Stack&nbsp;Overflow than the percentage of female programmers.    Assuming that is the case, then Stack&nbsp;Overflow is geared more towards the male psyche than the female. If so, I again ask, what can they do about that?      This question was asked in StackOverflow Meta on November 20, 2009. It was made Community Wiki. It was asked in a constructive manner and should be considered an appropriate question for Meta.   Yet it was closed over two years after it was asked as "not constructive" after more than 40 upvotes and 10 favorites and 16 answers.   Now it resides here on Meta StackExchange, still closed. I just shake my head. How could I adjust the size and placement of chapter heading in my custom class? I am using report class as my base. When I used titlesec package inside my custom class, it threw error     ! Package titlesec Error: Not allowed in `easy'   settings. What's the easiest way to run GUI apps on Windows Subsystem for Linux as of 2018? How do I assign the output of a command to a variable? Best word for "unable to change" What is the trajectory of a photon moving through a vacuum? Since electromagnetic energy is carried by photons and moves in forms of waves, does it mean that a single photon when propagating through space doesn't follow the straight path but instead always moves up and down, up and down like a wave. If so another question arises the speed of propagation of light in vacuum is fixed meaning that it will always take the same amount of time for it to travel from point A to point B, but if a photon always moves up and down it will also mean that it travels longer distance than the distance between A and B and so it ill travel faster than light propagates, is it even possible, could you please clarify these concepts for me? Capacitor discharging through no load? What exactly would happen in the ideal case where a capacitor were to discharge into a wire with zero resistance?  Like in here:  There is still charge on one plate of the capacitor, which will try to go to the other plate to make $\Delta V = 0$ across the capacitor, so there has to be a current $I$.  But as more charge goes to the other side of the capacitor, the more repulsion these will cause to more coming towards them. So I am assuming current cannot just be constant?  I am starting from $$ I = C \frac{dV}{dt}, $$ but I know neither $V(t)$ nor $I$. Allowing only one download per Apple ID What is the best practice for multiple button placement and emphasis? Usually, we only have 2 buttons at the bottom of a form or a page that requires an action: Submit &amp; Cancel.  This one is quite easy to style. However, what if we are dealing with multiple buttons at the bottom of a page? For example:   ← Back | Send Email | Booking Paid | Check-in Guest   I'm thinking of making "Back" just a link (not a button) and making "Send Email" / "Booking Paid" secondary buttons (light gray). Then I'd make "Check-in Guest" as the primary button (green).  I still feel that there's a better way of doing it or dealing with multiple buttons / actions. What do you think?