nullpointerexception

Primefaces JSF null returned from RequestContext.getCurrentInstance()

烈酒焚心 提交于 2019-12-13 12:32:40
问题 I'm developing an app using Primefaces tag library. So far I've copied some examples from their official website and all seems to work except for anything that uses the RequestContext.getCurrentInstance() method. It either returns null every time, causing Tomcat to throw a NullPointer exception or hangs forever, never returning anything. Here's my code (the case where it hangs): GlobalCounterBean.java package org.primefaces.examples.view; import java.io.Serializable; import org.primefaces

Best practise in catching and throwing nullpointerexception?

佐手、 提交于 2019-12-13 12:08:52
问题 It seems like it is not a good idea to catch a nullpointerexception. If that's the case, why is it thrown by methods? Should it just be caught with Exception? Also, if I encounter a parameter which is null (can either be primitive type like string or a class with fields), how should I handle it? (assumingly not throw npe)? Thanks 回答1: A nullpointerexception usually indicates a programmer error. You won't catch a null pointer exception if you don't expect such a programmer error. For instance,

Android onClickListener NullPointerException

我怕爱的太早我们不能终老 提交于 2019-12-13 11:28:31
问题 all. I've searched, but can't find anything that helps me fix this problem. My app quits almost immediately on launch due to a NullPointerException. I suspect maybe the problem is that I'm using a drawable image (ImageView) rather than a button (View) as the thing you click on. Thanks for any help. This has been driving me bonkers for hours! Code is as follows: package com.example.imageswitchermk2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android

Issue with NullPointerException in Java [duplicate]

独自空忆成欢 提交于 2019-12-13 11:26:04
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 8 months ago . I'm having problems with a NullPointerException. I was doing the debugging and the element is not null, I have the problem in the first IF and I can not see what the problem is. I thought that happened when the state of the element was null, but I tried to fix it and it did not work // Update: The problem is when I Check the status for (Items item : master.getItems(

Android SDK Null point Exception [duplicate]

大城市里の小女人 提交于 2019-12-13 11:25:49
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed last year . I am having a following error: Can anyone solve this Debugger: AdroidRuntime: FATAL EXCEPTION: main Process: com.example.avishek.wifidirect, PID: 8053 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.avishek.wifidirect/com.example.avishek.wifidirect.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android

nullpointerexception array.length java

坚强是说给别人听的谎言 提交于 2019-12-13 11:24:43
问题 I've been getting an NPE whenever i try to access my array. Even calling for the .length attribute gives me an NPE. Any help would be appreciated. Here is my constructor and the method that keeps failing. public SkierList() { Skier[] skiers= new Skier[INITIAL_CAP]; for (int i = 0; i < skiers.length;i++){ skiers[i] = new Skier(""); } int count = 0; } public void add(Skier newSkier) { if (this.size() < skiers.length) { skiers[count] = new Skier(newSkier.getName(), newSkier.getLevel()); count++;

Cannot access an Object Reference instantiated by a sibling class

白昼怎懂夜的黑 提交于 2019-12-13 10:47:56
问题 I have an abstract class that declares a number of object references, specifically a JLabel. I have two classes that both extend that class. One of the children instantiates the JLabel and calls a couple of its methods. That classes sibling attempts to call the setText method on the JLabel and I get a NullPointerException(The sibling that instantiates it is called before the other.) I had thought that all children refer to the same object in memory and would thus modify the same object but

Dynamic inflating gives me a nullexception

≯℡__Kan透↙ 提交于 2019-12-13 10:41:09
问题 I'm making a layout with a LinearLayout. This layout will have another layout inflated inside. Currently, I'm getting problems (nullexceptions) with that. My inflating code is the next: private void addLayoutInvoices() { LinearLayout ll_invoices = new LinearLayout(getActivity()); ll_invoices.setGravity(Gravity.CENTER); ll_invoices.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout

Why view return null in android [duplicate]

余生颓废 提交于 2019-12-13 10:34:51
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 3 years ago . I have 3 activity that display listview and it has an image to display icon and textview to display data. I want to make an adapter that can use general for my listview on these activity. But when I run my app, the logcat show me null pointer exception. 08-25 22:43:04.090 28942-28942/com.example.xiaoking.dilibus A/art: art/runtime/thread.cc:1113] Throwing new

SharedPreferences in non activity class NullPointerException [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-13 10:22:24
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed last year . I'm trying to use SharedPreferences in a non activity class from onResume() in an activity but I'm getting a NullPointerException on the context . For some reason I cannot get the context in onResume() . Not sure if I'm missing something, but any help would be appreciated. onResume() Method in my activity @Override protected void onResume() { super.onResume(); // The