nullpointerexception

Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference

二次信任 提交于 2021-02-05 11:21:45
问题 Basically this app is supposed to ask for your name, with an option to save, which when click, an alert dialog pops up and asks 'are you sure?', when yes is clicked, it should say 'welcome + whatever name put'. my problem is that the app keeps shutting down before it says welcome. I declared the string as userName and ran it without any function to the string, and it just said 'welcome, null'. but when i did userName=editText.getText().toString(); the app shut down immediately. Please HELP I

Null pointer exception on button click

半城伤御伤魂 提交于 2021-02-05 11:15:10
问题 I have 4 images as buttons and when the correct button is selected, an arrow button appears which is working fine. My problem is that I'm trying to change the background resource of each button to change when this arrow is clicked but I'm getting a null pointer exception at this line : happybutton.setBackgroundResource(R.drawable.mum1); I have declared the nextArrow button in my java onCreate - nextArrow = (Button) findViewById(R.id.nextArrow); nextArrow.setOnClickListener(onClickListener);

java multi-dimensional array fails with a nullpointerexception

佐手、 提交于 2021-02-04 21:37:18
问题 I get nullpointerexception when I try to fill a 2D array with process IDs, it is 2D since there is a unlimited list of PIDs for each system and I need to eventually return that back to my main code (set to void now since just a prototype test function). Any ideas would be great private void testfunctionA (List<String> additionalPC) { // A 2d array that will contain a list of pids for each system - needs to be strings and not integers String[][] pidCollection = new String[additionalPC.size()][

Android null pointer exception on ArrayList for ListView

强颜欢笑 提交于 2021-02-04 21:30:18
问题 I have a listview that shows the contents of an arraylist. I'm using a simple adaptor to make this possible like so. public static ArrayList<String> homeScreenContacts = new ArrayList<String>(); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.home_screen_contacts_view, NewContact.homeScreenContacts); The second line is giving me a null pointer exception. I thought about it and I decided it was because the arrayList is empty. So I added the following line between the

Cannot invoke “javafx.scene.control.ComboBox.getItems()” because the return value of “Controller.getMyBox()” is null

為{幸葍}努か 提交于 2021-01-29 14:10:06
问题 Somehow, I cannot add items to my ComboBox variable from another class as it always says either the value of variable is null or the return value of its getter is null. I use Scene Builder to build Sample.fxml, with controller as Controller class, luanch the whole thing form UserInterface class FXML <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.ComboBox?> <?import javafx.scene.layout.BorderPane?> <BorderPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http:/

Android NullPointerException - Debugging a specific line

别说谁变了你拦得住时间么 提交于 2021-01-28 08:48:24
问题 If I have a line like this: var.getSomething().getSomethingElse().setNewValue(stuff.getValue().getWhatever()); If that line creates a NullPointerException , is there any way of finding out which method is returning a null value? I believe I was able to split the line at every dot and get the exception showing which line was failing. But I can't get that to work anymore (maybe I remember incorrectly). Is the only good debugging possibility to write it like this? a = var.getSomething(); b = a

Mocking a file, filewriter and csvwriter within a method for unit test throwing NullPointerException

限于喜欢 提交于 2021-01-28 00:05:30
问题 I'm trying to mock a file creation , FileWriter operation and CsvWriter operation. I'm using EasyMock to mock file creation , PowerMockito to mock FileWriter and CSVWriter operations. Even after mocking the file creation, junit showing NullPointerException.. My code is, package example.mypackage.rms.utility; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import au.com.bytecode.opencsv.CSVWriter; public class CSVBeanUtil { public static boolean

Null pointer exception when using Bundle to pass data

不问归期 提交于 2021-01-27 05:41:47
问题 I've got a float array camObjCoord declared as.. public static float camObjCoord[] = new float[8000]; I'm then filling it's indexes in a class that does something like the following.. camObjCoord[1] = 2.5; I'm then calling makeview() public void makeview() { Intent myIntent = new Intent(this, GLCamTest.class); this.startActivity(myIntent); Bundle b = new Bundle(); b.putFloatArray("tweets", camObjCoord); } and then in the new class it's doing... public void onCreate(Bundle savedInstanceState)

How to use interface to communicate between fragment and activity?

痴心易碎 提交于 2021-01-05 07:32:42
问题 I simply want to call a Fragment method from my MainActivity. So I tried to use an Interface. public interface MyInterface { void testMethod(); } In my Fragment (TestFragment.java) I implement the interface and overrite the testMethod method. @Override public void testMethod() { Toast.makeText(getActivity(), "Test", Toast.LENGTH_LONG).show(); } but now I want to call this method from my MainActivity as soon as the onRewardedVideoCompleted get's called, but I'm not sure how to do it. I tried

Attempt to invoke virtual method 'boolean java.util.ArrayList.add on a null object reference

僤鯓⒐⒋嵵緔 提交于 2021-01-01 04:08:30
问题 I'm creating an Android application. The problem is that when I press the button and pass the data to the new array, it goes to black and giving me this error: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add (java.lang.Object) 'on a null object reference By debugging, it gives me something in the string: mExampleList.add(Ticket) My ExampleAdapter class: public class ExampleAdapter extends RecyclerView.Adapter<ExampleAdapter