nullpointerexception

What is a NullPointerException, and how do I fix it?

孤街浪徒 提交于 2020-01-06 05:42:14
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. 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? 回答1: When you declare a reference variable (i.e. an object) you are really creating a pointer to an object. Consider the following code where you

Unit Test - Simple assert is giving null pointer exception error [duplicate]

て烟熏妆下的殇ゞ 提交于 2020-01-06 05:33:28
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 11 months ago . I am writing a unit test to verify that both the ISO8601Utils (deprecated class which I replaced with SimpleDateFormat) and SimpleDateFormat has the same format. My class: public static class ISO8601DateFormat extends DateFormat { public static final long serialVersionUID = 3549786448500970210L; public ISO8601DateFormat() {} @Override public StringBuffer format

ViewPager.setCurrentItem responsing NullPointerException

假装没事ソ 提交于 2020-01-06 04:39:04
问题 I have implemented ViewPager and fragment(say A, B, C, D, E) as an child. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mSectionsPagerAdapter); // FragmentStatePagerAdapter after then I called mViewPager.setCurrentItem(3, false); which is giving NullPointerException. Following log: java.lang.NullPointerException E/AndroidRuntime( 330): at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:116)

Java/Android NullPointerException on onClick

早过忘川 提交于 2020-01-06 03:31:06
问题 I have no idea why Android/Java is doing this, It's kind hard to think as I'm extremely tired and literally can't think for myself at this current time. I'm creating static functions and imputing and executing the code that way, I don't think that's the reason as it hasn't even got past the if statement yet; what do you all think? I bet it's an easy solution, I just can't figure it out for the life of me. Code: public class LogIn extends Activity { Button login; EditText user; EditText pass;

NullPointerException in Java when using an object as a field

非 Y 不嫁゛ 提交于 2020-01-06 02:35:06
问题 I'm pretty new to Java, as my post might give away. I need to create a class (let's call it class A) which uses another class (class B) as one of its fields. Class A's constructor calls class B's constructor. So far things work fine. But when one of A's methods tries to use one of B's methods on the object of class B, I get a NullPointerException. This is probably too confusing so I wrote this simple example which creates the Exception. This is class B: public class class_B { private int y;

Pass String between two fragments without using an activity

不想你离开。 提交于 2020-01-05 15:42:15
问题 I need to pass the string curDate between NewDateFragment and NewEventFrament, i see many peoples using Bundle, but using these i still having NullPointerException. I transform the CalendarView to one string named curDate. public class NewDateFragment extends Fragment { public String curDate; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle

fManager.getFragmentById() returns null

♀尐吖头ヾ 提交于 2020-01-05 09:34:36
问题 I asked a question like this one the other day... this. I marked it as resolved, because the mistake was that isPlayServicesAvailable() returned false, because I had not the up to date Google Play Services. I have them now...but still NPE. The code: GoogleMap map; FragmentManager fmanager = getSupportFragmentManager(); Fragment fragment = fmanager.findFragmentById(R.id.map);//after this, fragment is null SupportMapFragment supportmapfragment = (SupportMapFragment)fragment; map

NullpointerException with connection object creating SQL statement

断了今生、忘了曾经 提交于 2020-01-05 08:54:11
问题 I am getting a nullpointerexception with this line of code Statement stmt = conn.createStatement(); The servlet that uses this was working ok a few days back and I recovered from a previous version of my class from my repository and it still is not working , so I am guessing it is maybe a server side problem. However to be sure I want to get as much information as possible , what would be the best way to debug. I have tried using e.toString() However this only gives "nullpointerexception"

NullpointerException with connection object creating SQL statement

孤街醉人 提交于 2020-01-05 08:54:11
问题 I am getting a nullpointerexception with this line of code Statement stmt = conn.createStatement(); The servlet that uses this was working ok a few days back and I recovered from a previous version of my class from my repository and it still is not working , so I am guessing it is maybe a server side problem. However to be sure I want to get as much information as possible , what would be the best way to debug. I have tried using e.toString() However this only gives "nullpointerexception"

NullPointerException thrown in java synchronised method using sockets

跟風遠走 提交于 2020-01-05 08:12:39
问题 I have an android app written in java. The app basically connects to a device which sends the app messages. The app waits for the messages to come in and then reports them, before processing each message. I have a Connection class and a Listener class. The Connection class is started via the constructor, which sets up the Listener class to listen for messages coming in from the device. When a message comes in, the Listener sends the message to a method in the Connection class, reportMessage()