nullpointerexception

NullPointerException with AppCompat BottomSheets

吃可爱长大的小学妹 提交于 2019-12-29 08:27:54
问题 LinearLayout bottomSheetViewgroup = (LinearLayout) findViewById(R.id.bottomSheet); bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetViewgroup); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); //this line I have this code within my activity's onCreate() method and I'm getting the below NPE exception when the last line is executed: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null

Nullpointerexception thrown when trying to findViewById

ぐ巨炮叔叔 提交于 2019-12-28 07:16:24
问题 I have the following Activity: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new StartFragment()) .commit(); } Button login = (Button) findViewById(R.id.loginButton); login.setOnClickListener(new View.OnClickListener() { @Override public void

NullPointerException at openFileOutput in Activity

久未见 提交于 2019-12-28 07:05:22
问题 I have an Activity with an ImageView, which, if it is empty and clicked, should load an image from Internet and save it to internal storage. So the activity looks like this: public class PlaceCreate extends Activity { Context context; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.create); context = this; ImageView img = (ImageView) findViewById(R.id.imageView); img.setOnClickListener(new OnClickListener() { public void

NullPointerException at openFileOutput in Activity

会有一股神秘感。 提交于 2019-12-28 07:05:06
问题 I have an Activity with an ImageView, which, if it is empty and clicked, should load an image from Internet and save it to internal storage. So the activity looks like this: public class PlaceCreate extends Activity { Context context; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.create); context = this; ImageView img = (ImageView) findViewById(R.id.imageView); img.setOnClickListener(new OnClickListener() { public void

String.split returning null when using a dot

我与影子孤独终老i 提交于 2019-12-28 06:27:30
问题 I got this simple code: String ip = "1.2.3.4"; String[] ipArray = ip.split("."); System.out.println(ipArray[1]); And ipArray is null by the time it hits System.out.println (throws null pointer exception). My question is why does ipArray stay null even though I'm setting it to split on each of ip's .s? 回答1: Use ip.split("\\."); and your problems will be solved. The problem is that String#split receives a regular expression, the dot (.) symbol is a special character in regular expressions, so

Find out what variable is throwing a NullPointerException programmatically

二次信任 提交于 2019-12-28 05:50:10
问题 I know I can find out if a variable is null in Java using these techniques: if (var==null) -> too much work try { ... } catch (NullPointerException e) { ...} -> it tells me what line is throwing the exception using the debugger -> by hand, too slow Consider this line of code: if (this.superSL.items.get(name).getSource().compareTo(VIsualShoppingList.Source_EXTRA)==0) { I would like to know if there's a generic way to find out programatically what variable (not just the line) is throwing the

nullpointer exception raises when i click on the button

断了今生、忘了曾经 提交于 2019-12-28 04:37:25
问题 When I click on CheckData button on android, it is throwing a nullpointer exception . SaveData.java public class SaveData extends Activity implements OnClickListener { static final int DIALOG_ID = 0; private Uri mImageCaptureUri; private ImageView mImageView; public static class Certificates { private Bitmap bmp; public Certificates(Bitmap b) { bmp = b; } public Bitmap getBitmap() { return bmp; } } private static final int PICK_FROM_CAMERA = 1; private static final int PICK_FROM_FILE = 2;

Filter values only if not null using lambda in Java8

断了今生、忘了曾经 提交于 2019-12-28 03:21:25
问题 I have a list of objects say car . I want to filter this list based on some parameter using Java 8. But if the parameter is null , it throws NullPointerException . How to filter out null values? Current code is as follows requiredCars = cars.stream().filter(c -> c.getName().startsWith("M")); This throws NullPointerException if getName() returns null . 回答1: In this particular example I think @Tagir is 100% correct get it into one filter and do the two checks. I wouldn't use Optional.ofNullable

Eclipse / Android : “Errors running builder 'Android Pre Compiler' on project…”

天涯浪子 提交于 2019-12-27 11:57:08
问题 Attempting to do some work on an Android project I haven't worked on for a couple of months, yet every time I attempt to build the project Eclipse throws up a dialog saying: 'Building workspace' has encountered a problem Errors occurred during the build. Errors running builder 'Android Pre Compiler' on project 'XXX' java.lang.NullPointerException I'm running Eclipse on a Mac with an Android project build target 4.0.3 (API Level 15) and I've the following versions of things installed Eclipse -

Eclipse / Android : “Errors running builder 'Android Pre Compiler' on project…”

早过忘川 提交于 2019-12-27 11:56:33
问题 Attempting to do some work on an Android project I haven't worked on for a couple of months, yet every time I attempt to build the project Eclipse throws up a dialog saying: 'Building workspace' has encountered a problem Errors occurred during the build. Errors running builder 'Android Pre Compiler' on project 'XXX' java.lang.NullPointerException I'm running Eclipse on a Mac with an Android project build target 4.0.3 (API Level 15) and I've the following versions of things installed Eclipse -