FAQ Database Discussion Community


NullPointerExeption in loading records

java,nullpointerexception
I am reading records from file and loading them in an array of GameRecord. A single record consists of name(String) level(int) and score (int). The file contains these records with each record on single line and fields separated by a tab. I am getting a nullPointerException at line g[j].setName(rec[0]); Here...

How can I initialize web driver globally?

java,selenium-webdriver,nullpointerexception
I am working on automation using selenium webdriver , java. Getting nullpointerexception and it says driver is null. My code structure is given below : Package Utility Base Class Login Class App_constant Class Package Add user Add user Class Utility package code : package Utility; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public...

NullPointerException on return new[] [duplicate]

java,nullpointerexception
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers I have a very strange problem with NullPointerException. Code example is as follows: ... ... public String[] getParams(...) { ... ... ... ... 143 return new String[] {...

Null Pointer Exception ListWindow [duplicate]

java,list,nullpointerexception
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers Hi i am pretty new to this an it get a null pointer excepition at list.setSelectedIndex(0); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addListSelectionListener(new ListSelectionListener() [...] ) Does anyone knows what the problem is?...

Where does NullPointerException is thrown?

java,nullpointerexception,runtimeexception
If I'm doing something like this: String str = null; str.toLowerCase(); Here I will have a NullPointerException and I want to know where an exception will be created. Does JVM manage such cases and throws NullPointerException or at compile time there are some checks for that case in com.sun.tools.javac.code.Type class?...

Processing in Java Serial object Null Pointer Exception

java,nullpointerexception,serial-port,processing
First of all I am new to Java so I apologize if this is an obvious answer. I am using Processing in Java to read the input values coming from a usb port. Here is the custom class I set up to get the values. I call the getCurrentValue() method...

Cannot inject view to custom class with RoboGuice

android,nullpointerexception,roboguice
I started to use RoboGuice within my project. I can easily inject views inside fragments and activites but i have some trouble with cusom views. I got null ptr exception every time. According to RoboGuice's example i did the same with my custom class: TestActivity @ContentView(R.layout.test_layout) public class TestActivity extends...

how to get k nearest neighbors using weka kdtree

java,nullpointerexception,weka,nearest-neighbor
I'm trying to get k nearest neighbors using weka KDTree implementation like this: ArrayList<ArrayList<Double>> ar = new ArrayList<ArrayList<Double>>(); ArrayList<Double> d1 = new ArrayList<Double>(); d1.add(1.1); d1.add(1.1); ArrayList<Double> d2 = new ArrayList<Double>(); d2.add(2.2); d2.add(2.2); ArrayList<Double> d3 = new ArrayList<Double>(); d3.add(3.3); d3.add(3.3); ar.add(d1); ar.add(d2); ar.add(d3); Attribute a1 = new Attribute("attr1", 0); Attribute a2...

Getting java.lang.NullPointerException on customDialogBox

java,android,nullpointerexception,customdialog
I am getting java.lang.NullPointerException for this method. I have check the adapter and lists are just fine and the list is ofcourse under fragment_phonelist xml file. private void showCustomDialog() { final Dialog dialog = new Dialog(SetupProfile.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.fragment_phonelist); Button done = (Button)dialog.findViewById(R.id.btn_done); Button canCel = (Button)dialog.findViewById(R.id.btn_cancel); ListView PhoneListView = (ListView)findViewById(R.id.list_phone);...

No NullPointerException in JSTL when calling methods on null object associated with request object.why?

java,jsp,servlets,nullpointerexception,dispatcher
Yesterday I appeared in an interview. The interviewer shows me this code and asked- <c:when test='${hobby.equals("hobby1")}'> Why there is no null pointer, while the value of hobby is null Code is as- In Sevlet class- request.setAttribute("hobby", null); request.getRequestDispatcher("display.jsp").forward(request, response); In display.jsp- <c:when test='${hobby.equals("hobby1")}'> ...

Android: Data is available still getting error NullPointerException

java,android,json,sqlite,nullpointerexception
I am new in android development..I want to insert json string in Sqlite database and getting error : java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1212, result=0, data=null} to activity : java.lang.NullPointerException. here is my code : DbAdapter.java static final String DATABASE_FEEDBACK="CREATE TABLE IF NOT EXISTS "+" feedbackjson "+ "("+"FeedbackId"+" integer primary...

Validating Blank EditText shows error

android,nullpointerexception,android-edittext,android-alertdialog
While I am validating EditText for login I am Getting NullPointerException public boolean onMenuItemClick( MenuItem item ) { if(item.getTitle().equals("Login")) { final String Usname; final String Pswd; Status=(TextView)findViewById(R.id.tvStatus); Uname=(EditText)findViewById(R.id.etLUsername); Pwd=(EditText)findViewById(R.id.etLPassword); LayoutInflater li = LayoutInflater.from(MainActivity.this); View promptsView = li.inflate(R.layout.login, null); //Usname=Uname.getText().toString(); //Pswd=Pwd.getText().toString();...

AudioManager setStreamMute() Null Pointer Exception

android,nullpointerexception,android-audiomanager
I am getting Null Pointer Exception on line 219: amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);. It was not happening before, today i saw it first time, i am using Android 5.0. Code mutes notification sound when activity starts and unmutes when it is destroyed. Code: private AudioManager amanager; @Override protected void onCreate(Bundle savedInstanceState) {...

Can't figure out how to deal with these errors [duplicate]

java,swing,exception-handling,nullpointerexception,thread-safety
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers i built a little software. The software runs perfectly ok as it should. On initiation of the software, a option pane pops up asking for name, user can...

List files in a folder to a JOptionPane

java,nullpointerexception,java-io
Lately I have been working on a program to list the files in a folder so they show up on a JOptionPane. I have tried to get a File[] by calling File.listFiles on the folder object, but it results a NullPointerException on line for (int i = 0; i <...

java.lang.NullPointerException at com.sun.ejb.codegen.EjbOptionalIntfGenerator.generateSubclass(EjbOptionalIntfGenerator.java:280)

java-ee,nullpointerexception,glassfish,ejb,subclass
So I was using EJB to create users in DB. It worked. So after that I made a profile page that user can change. Unfortunately I'm hit with an NPE because the EJB can't load. So I've another @Stateless class and that I pretty much copy pasted to create this...

addition of distinct substrings of multiple strings to a Treeset

java,string,nullpointerexception,runtime-error,treeset
Question - You are given n strings w1, w2, ......, wn. Let Si denote the set of strings formed by considering all unique substrings of the string wi. A substring is defined as a contiguous sequence of one or more characters in the string. More information on substrings can be...

Null Pointer Exception while setting value of TextView in an Array Adapter class - Android

java,android,listview,android-listview,nullpointerexception
I'm getting a NullPointerException while trying to start an Activity which contains a ListView . In the getView method of the adapter class, the exception happens when the setText function of a textView is being called . The code bellow is my adapter class: public class QuestionsListAdapter extends ArrayAdapter<Question> {...

List of custom object and Parcelable give NullPointerException

java,android,nullpointerexception,parcelable
I am trying to understand principles of Parcelable in Android and I wrote this simply code to find what is going on when I try to "parcel" a list of custom object - it gives my NullPointerException Here is my code : package cz.united121.android.testpupose.Objects.HelperObject; import android.os.Parcel; import android.os.Parcelable; public class...

Android Volley Crashing

java,android,nullpointerexception,android-volley
I'm using Android Volley to login a user in but when addToRequestQueue is called the following crash report is shown. The login request is carried out onclick in the Loginactivity as follows: // Login button Click Event btnLogin.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { String username = inputUserName.getText().toString(); String...

NullPointerException while populating an Array or a list

java,arrays,list,nullpointerexception
I'm trying to populate an array with the another array of values and doing the same with lists but getting null pointer exception for arrays and nothing happened using the list. below is the code snippet: public class EMPTest { public static void main(String[] args) { //Array EMP[] emps =...

Reading Andriod File Returns NullpointerException

java,android,nullpointerexception
06-20 14:28:08.742 3156-3156/org.jaberrio.personai2 W/System.err﹕ java.lang.NullPointerException 06-20 14:28:08.742 3156-3156/org.jaberrio.personai2 W/System.err﹕ at java.lang.String.<init>(String.java:228) 06-20 14:28:08.742 3156-3156/org.jaberrio.personai2 W/System.err﹕ at org.jaberrio.personai2.DataBaseManager.getDataBase(DataBaseManager.java:37) 06-20 14:28:08.742 3156-3156/org.jaberrio.personai2 W/System.err﹕ at org.jaberrio.personai2.OverviewLand.onClick(OverviewLand.java:93) 06-20 14:28:08.742...

Android: Can't figure this exception

android,nullpointerexception
This is my exception log java.lang.NullPointerException at android.view.GestureDetector.onTouchEvent(GestureDetector.java:587) at android.widget.Gallery.onTouchEvent(Gallery.java:937) at android.view.View.dispatchTouchEvent(View.java:5541) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) at...

Qoppa PDF Android NullPointer

android,pdf,nullpointerexception,pdf-viewer
I`m trying qoppapdf in my App and it runs into an NullPointer in the following code: PDFDocument pdf = null; try { pdf = new PDFDocument(url, null); } catch (PDFException e) { e.printStackTrace(); } PDFPage page = pdf.getPage(0); The error reads: 06-01 17:29:59.687 24761-24761/app W/dalvikvm﹕ Exception Ljava/lang/NullPointerException; thrown while initializing...

v7 getSupportActionBar() is throwing NullPointerException

java,android,nullpointerexception,android-support-library
I'm launching a new activity (TVMPDFActivity) from my root activity. I'm using Android Annotations, so this is how I'm launching the Activity: TVMPDFActivity_.intent(this.getActivity()).start(); TVMPDFActivity is a subclass of PDFPreviewActivity which is a subclass of ActionBarActivity. A NullPointerException is being thrown from onCreate in PDFPreviewActivity when I simply try to GET...

JOptionPane throwing error when cancelled

java,nullpointerexception,joptionpane
Currently having an issue where I am popping a message dialog up to prompt the user to enter a string. I have a check for the name being empty which works properly if they hit the "ok" button however if the user hits the cancel button (whether they input anything...

Getting null pointer with recycler adapter

nullpointerexception,fragment,recyclerview,android-recyclerview,recycler-adapter
my app is crashing due to a null pointer with the recyclerview adapter in the fragment code. I'm using this adapter to generate a card view list but cannot find out what exactly is causing this null pointer. The log has it happening when setting the adapter r.setAdapter(rA) in the...

In Java, how can I fix this nullPointerException in a while loop?

java,loops,while-loop,nullpointerexception,null
In a java file I'm consistently having a runtime error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at a line with a while loop and need to find a way to avoid this nullPointerException. My current code at this line looks like this : while (b.isOnBoard(row-i, col-i) && b.getState(row-i, col-i).equals(yourcolor)) { count++;...

Null Pointer Exception When Autowiring Class

java,spring,nullpointerexception,autowired,shiro
I am building a REST API using Spring Boot with Shiro for authentication. I am getting a NullPointerException when I try to Autowire a repository in my realm code. Autowiring the repository elsewhere does not produce this error. Here is my authorizing realm: @Component public class CCDAuthorizingRealm extends AuthorizingRealm {...

Runtime errors when method is invoked?

java,android,error-handling,nullpointerexception,gps
I'm having some issues when I am running my method. How can I get it working so my mock locations will work on my actual device. (Ps. I've included permissions). This provides a null pointer exception and I am not to sure why? Method: private void setMockLocation() { { Context...

NullPointerException in CustomArrayAdapter

java,android,nullpointerexception,android-arrayadapter
I'm trying to use a Custom Array Adapter to populate a ListView in in a Fragment. But I'm getting NullPointerException on method findViewById() in getView() method in Custom Array Adapter. Here is the CustomAdapter.java : package graph.prathya.com.materialdesign; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import...

Why can this function return a null possibly?

java,nullpointerexception,guava
Imagine I had a guava helper function private Function<Config, Predicate<String>> makeFunctionToCompareTwoPathStrings() throws ConfigException { return new Function<Config, Predicate<String>>() { @Override public Predicate<String> apply(final Config config) { try { final Path input = computationThatMightThrowAnException(); return new Predicate<String>() { @Override public boolean apply(String actual) { return input.toAbsolutePath().toString().equalsIgnoreCase(actual); } }; } catch (ConfigException...

Chaining Null-Safe Operator

groovy,nullpointerexception
My project has code like the following: params.stringValue?.trim().replaceAll('aa', 'a') We expected that if params.stringValue was null, that both trim() and replaceAll() would not be called. However we were getting a NullPointerException on this line saying that replaceAll() cannot be called on a null Object. We had to change the code...

Android: What is wrong with my custom viewHolder?

android,nullpointerexception
I've used a custom ViewHolder class to instantiate views. I'm getting NullPointException on this code. Application runs fine if I comment out iconView.setImageResource and descriptionView.setText() lines in bindView function. If two of them showing NullPointExcepttion, why not the rest? ADAPTER CLASS: private final int VIEW_TYPE_TODAY = 0; private final int...

Why am I getting a NullPointerException when trying to use the reference of Activity from a Fragment?

android,android-fragments,nullpointerexception,android-context
I have a method that does a Facebook call for a user's profile info. And one of parameters is a Context. I am passing in the Activity's context from a Fragment, but some of my users are getting a NullPointerException for the context. I am saving the reference of the...

Null Pointer Exception in Android

android,nullpointerexception
I am new to android programming. I've tried to make reminder application. But when I added alarm manager to my codes. It gave me NullPointerException. I have checked the question asked before. But they didn't help me. I also checked if there was the thing that I didn't initialize. But...

Android: Attempt to invoke virtual method (onTouch) on a null object reference

java,android,nullpointerexception
I'm trying to set up gesture detection on one of the Linear layouts on a view in my app. The problem is my app crashes whenever I test it with a fling gesture. The error message I receive is the notorious "Attempt to invoke virtual method on a null object...

How to paint over a JPanel?

java,swing,graphics,nullpointerexception,jpanel
I (A novice programmer) am trying to paint an oval over a JPanel. I am trying to use the method paint. However, it requires a Graphics argument. I get a NullPointerException when I include my Graphics as a argument because it is null, but I do not know how else...

List shows as not null but ArrayAdapter throws NullPointerException

java,android,android-listview,nullpointerexception,android-arrayadapter
Can anyone please help me? I just don't understand why does it throw null pointer exception. I work with ksoap2,WCF web methods and android. I checked the "list" in debugger mode and it is not null. Here is my code: public class MainActivity extends Activity { String loginMemberId = "a001";...

NullPointerException Warning on getView() inside onActivityCreated/onStart/onViewCreated method

java,android,android-studio,nullpointerexception,getview
I know getView() might return null inside onCreateView() method, but even if I put the below code inside onActivityCreated(), onStart() or onViewCreated() methods, it still shows the warning about a possible NullPointerException in Android Studio (although my program runs without any issue). How to get rid of this warning? I...

Really strange NullPointerException in RoboVM

ios,nullpointerexception,robovm
If I call the following RoboVM method with any non-null argument: public static void runOnUiThread(final Runnable runnable) { System.out.println("Inside runOnUiThread():"); System.out.println(" Null-check: "+(runnable==null)); NSOperation operation = new NSOperation() { @Override public void main() { System.out.println("Inside main():"); System.out.println(" Null-check: "+(runnable==null)); runnable.run(); // NullPointerException here?!? How??? System.out.println(" main() completed"); } };...

Fatal Exception Main Android Null Pointer Exception

android,exception,nullpointerexception,main
I am having an issue with this weather app that I am making with TreeHouse I have asked a question on their forums, but no avail. Here are my two files in question... MainActivity package com.megliosolutions.stormy; import android.content.Context; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log;...

Null Pointer Exception adding null check [duplicate]

java,nullpointerexception,null
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers Simple and best way to solve Null pointer exception at this line: oS = ((SyIntBVO)syIntBVOList.get(0)).getSource().trim(); Exception on getSource variable. how to add null check?...

Comparable and (MyClass)null

java,nullpointerexception,null,compare,comparable
Say I have public class MyClass implements Comparable<MyClass> { public int compareTo(MyClass mc) { //<implementation ommited>... } } The docs for Comparable say that "The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value...

How to fix Null pointer exception [duplicate]

android,nullpointerexception
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers I am writing an android application that consists of a alertdialog and i am getting a null pointer exception.I cant find any exceptions in my code but it...

Android App Development “NullPointerException on setBackgroundResource(xx)”

java,android,xml,nullpointerexception
Im trying to make an app for a frisbee golf club. With this app i am using this tutorial to make a gallery swiper to look though the diffrent courses. But when running the app i get a NullpointerException in my getView Method. I cant possibly understand why this is...

Socket DataOutputStream writeInt() method NullPointerException

sockets,nullpointerexception,dataoutputstream
I'm trying to send serialize class object on the server side. First I serialize object in byte array, then I take array length and send lenght as integer and send array on the srever side. But programm fold with NullPointerException in stacktrace. All class-fields is static. What a problem? public...

Behaviour of null in Java

java,nullpointerexception,null,concatenation
This probably looks duplicate of other questions on SO. But, I was wondering the way Java treat null. Eg: public class Work { String x = null; String y; Integer z; public static void main(String arg[]) { Work w = new Work(); w.x = w.x + w.y; // work Line...

NullPointerException on AppCompatActivity setContentView

java,android,nullpointerexception,appcompat-v7-r22.1,appcompatactivity
I'm getting an error that I don't really know how to explain. My app crashes when starting with the following exception: 05-18 19:49:36.815 6795-6795/com.ispimi.ispimi E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.ispimi.ispimi, PID: 6795 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ispimi.ispimi/com.ispimi.ispimi.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object...

spinner.setAdapter(adapter) causes “A resource was acquired at attached stack trace but never released” error and app force close

java,android,nullpointerexception
I am attempting to change the items in a spinner using the ArrrayAdapter, with spinner.setAdapter(adapter) This code runs when a sidebar item is selected, changing the values in the spinner @Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { String Tag = "Navigation drawer"; Log.v(Tag, "Drawer item toggled"); Spinner spinner...

Invalid user credential context after successful authentication

java,spring-mvc,authentication,spring-security,nullpointerexception
At the moment I have to write a Spring Web MVC based application. Because I need more controll over the login process, I re-implemented the AuthenticationProvider like this (Login is always successful): @Component public class LdapAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { List<GrantedAuthority> authority =...

Cannot add Button in second child in Sliding up Panel

android,nullpointerexception,slider
I have a sliding panel in my Layout. There is a button in first child which works fine but when I add a button in second child there is a NullPointerException thrown. If I remove the Button layout works just fine. I am not able to understand what I am...

How setText to custom dialog from one class in others?

java,android,nullpointerexception,dialog
I have created a dialog class that i would like to use in several other classes and depending in what class they should display different info. I have no problem displaying the dialog itself with working button and an already set text from the xml. But when i try to...

Null pointer exception at mSearchView.setIconified(false);

android,nullpointerexception,searchview,android-menu
I am getting null pointer exception at- mSearchView.setIconified(false); Why?? menu_home.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.peoplecloud.app.guggu.activities.HomeActivity"> <item android:id="@+id/menu_item_search" android:actionViewClass="android.widget.SearchView" android:icon="@drawable/icon_search" android:showAsAction="always" android:title="Giphy Search" > </item> </menu> Code- private...

How can i access the control in fragment in a tabed layout in android?

android,android-fragments,tabs,nullpointerexception
I create a project in android and use page view and fragment to create a tab layout and I create a control in each fragment (3 fragment) Now the problem is Here : In the main activity class in the oncreate() method I want to set text to a text...

Eclipse run my program well however JAR-file does not

java,eclipse,swing,jar,nullpointerexception
I have four classes in my game; Player.java, Game.java, Island.java and Map.java. And basically its plenty of code to link here however my issue is that my program works fine in eclipse but when i export as jar and run it nothing is opened so i open it with CMD...

Nullpointer Exception when using RecyclerView

android,nullpointerexception,recyclerview
I am following an android development tutorial (creating a weather app), but I am stuck at an error that I am getting I indlued the full logcat log at the end of the question. Does anyone has a clue why I am getting this error? I have checked everything more...

java null pointer exception JMenuBar [duplicate]

java,eclipse,swing,user-interface,nullpointerexception
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers Im stuck today with a java error on an eclipse 3.8 platform. I try to generate a simple MenuBar on a JFrame. The JMenuBar contains the JMenu("Help") and...

How to fill the treeTableView correctly

java,javafx,nullpointerexception,treetableview
I have a record in database which being get must be in the tree table view. Here is the filling method: private void updateGoods(){ goodsPane.setCenter(goodTreeTableView); List<Good> goodAndFoldersList; try { goodAndFoldersList = goodsService.getGoods();//database query }catch (SQLException e){ goodAndFoldersList = new ArrayList<>(); log.log(Level.ERROR, e.getMessage()); } List<Good> goods = new ArrayList<Good>();//list for roots...

NullPointerException ArrayAdapter adapter Android XML

java,android,xml,nullpointerexception
How are you? come with android problem, it is a NullPointerException ArrayAdapter adapter.Im a junior development, sorry. I have this code private String[] titulares; private ListView listadoTitulos; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Permisos StrictMode.ThreadPolicy permiso = new StrictMode.ThreadPolicy.Builder().permitAll().build(); //Damos los permisos StrictMode.setThreadPolicy(permiso); listadoTitulos = (ListView)...

Why am I getting null pointer exception in this program when using enhanced for loop

java,nullpointerexception
I am getting a null pointer exception in the selectAllStudent Method. When I am using foreach loop but When I am using a normal loop it is working fine. Please explain the reason. Thank you Driver Class import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Test { public static void...

I'm getting a NullPointerException when I click a button on my Android app

android,android-activity,nullpointerexception
I’m working on a simple Quiz app where the user is presented a question and can select either True or False to answer the question. I added a “Show Answer” button, but when I click on that button I’m getting the following NullPointerException. I think I'm missing something in my...

Android: Updating a menu item programmatically results in NullPointerException

android,nullpointerexception,menuitem
I am working on a RecylcerView and CardView. The cards contain ImageView. I also have an menu-item that is declared as an action and whose title is set to 0. What I want to achieve is that when I click on the image its position should be added to an...

null pointer exception on SharedPreferences

android,nullpointerexception,sharedpreferences
The first time users open my app, SharedPreferences might not be created. So I want to check if SharedPreferences has a value or not, and if it has no value (ie SharedPreferences has not been created) then create it and set its value. Here is my code: public static final...

NullPointerException: Attempt to invoke virtual method on a null object reference [duplicate]

java,android,nullpointerexception
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers im trying to implement a recyclerview with cardview in a fragment and im getting this error, im using android studio 1.0, i already check many post about this...

GoogleApiClient gives a nullpointer even when a context is passed to it while using Fused Location API in androd

android,nullpointerexception,android-fusedlocation,android-googleapiclient
I am trying to implement Fused Location API in a service. I have done the following coding but I am getting an error as follows: java.lang.RuntimeException: Unable to instantiate service com.locate.LocationDetails: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference at the following line of code:...

Android: JSONParser returns NullPointerException

java,android,nullpointerexception
I've read many other topics on SO from people who received the same exception, but none of the proposed solutions worked. So here's my problem: I'm trying to download a userlist from my database through a function in my app. The JSONParser keeps returning a NullPointException on this particular table...

UploadedFile is null when uploading file with

jsf,file-upload,primefaces,nullpointerexception
I need to upload an image into the server. I'm using primefaces, here is my code: deposit.xhtml <h:form> <p:fileUpload mode="simple" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" value="#{imageHandler.uploadedPicture}" /> <p:commandButton action="#{imageHandler.savefile(imageHandler.uploadedPicture)}" value="Déposer" ajax="false" /> </h:form> ImageHandler: @ManagedBean (name = "imageHandler") @RequestScoped public class ImageHandler { private UploadedFile uploadedPicture; // +getter+setter public void savefile(UploadedFile...

How to serialize the JPanel?

java,swing,serialization,nullpointerexception
So I have this code. And I'm trying to implement click to save on the JMenuBar and click to load. I am having trouble serializing the JPanel. How could I save the current plot view? the layout is set to AbsoluteLayout so the GroupLayout issue is not a problem. I've...

Internet Explorer WebDriver Null Pointer Exception [closed]

java,internet-explorer,selenium,nullpointerexception,webdriver
I am trying to run a test using the cross browser tool (using FF, Chrome and IE). FF and Chrome work fine, but i can't get Internet Explorer to work, it keeps giving me a null pointer exception (images included). So far I have tried using IE 11 backing up...

JavaFX - TableView successfully populated but NPE still occurs

javafx,nullpointerexception,tableview
I am populating my TableView with data from the database. When I select a row in the TableView(Tableview has listener) and then re-populate again the TableView, the data population is successful but a NPE occurs. I hope I expressed myself clearly. Sorry for the long post. ActionEvent @FXML private void...

multiple null arguments to a method taking varargs causes null pointer exception

java,nullpointerexception
I run into a null pointer exception when i run this: public class test { public static void main(String[] args) { Long a = getValue(); Long b = getValue(); Long c = sum(a, b); } private static Long getValue() { return null; } private static long sum(final long... values) {...

Android: NullPointerException when trying to load videoview through AsyncTask [duplicate]

java,android,android-asynctask,nullpointerexception,videoview
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers I created a fragment for my VideoView in my android project. I tried to load the VideoView with the video in my backgroundtask. My code: public class VideoPlayer...

Getting: “java.lang.NullPointerException” but I know object is instantiated in AsyncTask

java,android,android-asynctask,nullpointerexception
I am attempting to pass a string I got in an Asynchronous task class back in to my main activity, but when I pass the string result (which I know isn't null because logging the string right before passing it to the interface outputs what it should), I get a...

Android NDK socket creation null pointer

android,c,sockets,nullpointerexception,android-ndk
For adding TCP-socket-options, I need to use the C-sockets of Android NDK instead of Java sockets. The following function is called by a button-click-event. When creating such a socket, the syscall leads me to a null pointer (see log output at the end). As the log shows, the line above...

Adding textfield and label on mouse click not working Java

java,swing,nullpointerexception,jbutton,actionlistener
I have this code: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Interface2 { private JLabel label; private JLabel label2; private JLabel label3; private JTextField textfield; private JTextField textfield2; private JTextField textfield3; private JButton button; private JButton button2; private JButton...

Android studio “ Attempt to invoke virtual method on a null object reference”

android,nullpointerexception
when i create the custom view of each items of the list view, i get a null pointer exception and i dont know why, the layout id seems correct import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageView; import...

Getting a “java.lang.NullPointerException” while working whith Maps

java,dictionary,nullpointerexception,hashmap
I am trying to write a simple Diet program using maps with this code. But I keep getting NPE which keeps interrupting the process at random. What is wrong with my code? Why is that that I keep getting this error and how do I fix it? class Diet {...

NullPointerException when calling Bitmap.createBitmap

android,bitmap,nullpointerexception
I'm trying to get a bitmap drawn from a view, as I want to blur that bitmap and use it as a background for a following activity. Logcat gives me: NullPointerException at android.graphics.Bitmap.createBitmap(Bitmap.java:484) My code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the view from activity_main.xml setContentView(R.layout.activity_splash_page); ProgressWheel...

Recursion of Linked List

java,recursion,nullpointerexception,linked-list
When given an array of integers, I'm trying to change each element with the product of the integers before it. For example, int[] array = {2,2,3,4}; is now: {2, 4, 12, 48}; I added each element to a LinkedList, and I'm trying to do this recursively. This is what I...

Androi list view : Attempt to invoke virtual method on a null object reference [duplicate]

android,listview,nullpointerexception
This question already has an answer here: Android studio “ Attempt to invoke virtual method on a null object reference” 2 answers when i create the custom view of each items of the list view, i get a null pointer exception on the current wish that will be added...

Handling null values while extracting using java from MongoDB

java,database,mongodb,nullpointerexception
Frequently, I extract the data from mongo database using java (because I have to do it across very large number of collection across many databases). In the process, I generally use Eg: time = ((myObject.containsField("time"))) ? (myObject.get("time").toString().isEmpty()) ? "Empty" : myObject.get("time").toString() : "NA"; to make sure if the string exists...

Null Pointer Exception when writing to a File - Android Studio

java,android-studio,nullpointerexception
My app crashes every time I go to send the data gathered by the sensor. The error I am given is as follows: 06-20 14:50:00.784 22983-22983/com.example.adam.proj2 E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at com.example.adam.proj2.SensorActivity.onClick(SensorActivity.java:124) at android.view.View.performClick(View.java:3549) at android.view.View$PerformClick.run(View.java:14393) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at...

How to execute a return statement not working while handling an NullPointerException in hibernate

java,hibernate,nullpointerexception
This method must return an integer from a database query , which finds the maximum of column in a table. it will encounter a NullPointerException if there are no entries in table. I used try/catch blocks to handle NullPointerException. I need the method to return '0' when it catches a...

NullpointerException in Collection.sort() with multithreading

java,multithreading,nullpointerexception,executorservice
I have a class that should test my Fibonacci function using multithreading public class PerformanceTesterImpl implements PerformanceTester{ public static List<Long> executionTimesList = new ArrayList(); public static List<Runnable> tasksList = new ArrayList(); public int fib; public PerformanceTestResult performanceTestResult; @Override public PerformanceTestResult runPerformanceTest(Runnable task, int calculationCount, int threadPoolSize) { for(int i=0; i<calculationCount;...

Get a String from a JTextField through a JButton

java,string,swing,button,nullpointerexception
I am working on a program and I am almost done. What I want is: typing a String into a JTextField, press a JButton and I want the String to come out at the other JTextField. So I have: 2 JTextField and 1 Button. Here is my code: class Fenster...

null pointer exception on filling java fx table

java,javafx,nullpointerexception
I'm trying to set items to the @FXML private TableView<Price> pricesTable; where the following columns defined: @FXML private TableColumn<Price, Long> priceId; @FXML private TableColumn<Price, Good> priceGood; @FXML private TableColumn<Price, MeasurementUnit> priceMeasurement_unit; @FXML private TableColumn<Price, TypeOfPrice> type_of_price; @FXML private TableColumn<Price, Long> price; using such code: private void updatePrices() throws SQLException{ pricesPane.setCenter(pricesTable);...

Scala fails to initialize a val

scala,nullpointerexception
I have found kind of a weirdness in the following Scala program (sorry to include all the code, but you'll see why I added it all) : object md2html extends App { private val DEFAULT_THEME = Themes.AMAZON_LIGHT private val VALID_OPTIONS = Set("editorTheme", "logo", "style") try { // some code 1...

Activity cannot run due to the null pointer exception

android,android-fragments,android-activity,nullpointerexception,fragment
I created the code below import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Bundle; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; public...

JFrame: String changing back to null after the value is changed in the constructor

java,swing,netbeans,nullpointerexception,jframe
Just for clarification, i'm using JFrame Form in Netbeans. Ok so basically i'm trying to change the value of a public global String (PictureName) using the constructor, because i'm trying to take another value from another class, but when I try to use it in my JLabel's code, it appears...

Getting the variables for DesktopLauncher using Libgdx

java,nullpointerexception,get,libgdx
I am trying to create a 2d game and right now I need the games width. I tried to use Gdx.graphics.getWidth() but that gives me a nullpointer. After searching through the web I came upon this http://www.badlogicgames.com/forum/viewtopic.php?f=15&t=13984 That is the explanation but as you can see in my code I...

How to fix Null pointer exception in on clicking XML files in Eclipse IDE

android,eclipse,nullpointerexception
I am using Eclipse JUNO ADT for development of android applications. Suddenly I got an error: **An error has occurred. See error log for more details. java.lang.NullPointerException** while clicking on XML files in android.even i restarted eclipse and updated my eclipse IDE at admin mode it wont helps.Please help me...

NullPointerException URLImageSource.getConnection(URLImageSource

java,image,intellij-idea,nullpointerexception
i'm programming a project in IntelliJ IDEA on my Mac OSX. Everything works just fine when i run the code or when i export the jar and run it. But when i switch to windows, i get an error saying this: java.lang.NullPointerException at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:116) at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:126) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)...

merging xlsx files in java

java,nullpointerexception,apache-poi
i m trying to merge two .xlsx files to each other in java. But i m somehow getting a NullPointerException on the line if (cell.getSheet().getWorkbook() == mcell.getSheet() .getWorkbook()) { } Any ides what could cause this error ? when i tried before merging other two files, my code worked perfectly,...

java - NullPointerException in Graph

java,nullpointerexception,hashmap
I was trying to implement an undirected graph using a HashMap of ArrayList to represent the adjacency list. However, I got the null pointer exception error when I initialize the adjacency list, in which I was unable to identify the null pointer. Sorry for the stupid question but I'd appreciate...

Android Studio NullPointerException, trying to use parse.com

java,android,parse.com,nullpointerexception
I am trying to use Parse.com for the user login/signup activity for my apps, and I am learning how to use it by following this tutorial http://www.androidbegin.com/tutorial/android-parse-com-simple-login-and-signup-tutorial/ . But after I typed in everything, my app keep crashing and giving NullPointerException And here is my MainActivity package com.example.ed.parselogintutorial; import android.app.Activity;...

Java SWING Not Painting Properly

java,swing,nullpointerexception,paintcomponent,mouse-listeners
I'm having a problem with the JFrame not painting correctly. Can someone take a look at the solution please? I've tried using BoxLayouts but it wont work either. The buttons are not showing until I mouse over them. It's all in one file and executable. Regards package Executable; import java.awt.AlphaComposite;...

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

java,android,nullpointerexception
I'm getting error when runtime my project. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.olympic/com.prima.olympic.ProductDetail}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference This is full log : 06-06 23:12:45.561: E/AndroidRuntime(17135): FATAL EXCEPTION: main 06-06 23:12:45.561: E/AndroidRuntime(17135): Process: com.example.olympic, PID: 17135 06-06 23:12:45.561: E/AndroidRuntime(17135):...

Java exception detected in safari but not detected in IE?

java,internet-explorer,nullpointerexception,safari
I have a java applet code that works fine when it's opened from IE, but if it's opened from Safari, Java console produces a nullpointerexception. The code that generate this behaviour is shown below: public class MsgBoxPanel extends JDialog { Panel panel1 = new Panel(); JLabel label1 = new JLabel();...

NullPointerException when using setExitTransition to Fragment

android,android-fragments,nullpointerexception,transition
I am trying to animate my fragment's enter and exit. setEnterTransition works fine, but if I use setExitTransition, it throws a nullPointerException. If I use setReturnTransition, it doesn't show any animation. Here's what I have. private void showFragment() { Fragment fragment = JoinGroupFragment.newInstance(); FragmentTransaction ft = getFragmentManager().beginTransaction() .add(R.id.fragment_container, fragment, JOIN_GROUP_FRAGMENT_TAG);...