nullpointerexception

how to compare elements in a string array in java?

纵然是瞬间 提交于 2019-12-19 11:29:08
问题 I am trying to find duplicate words in a string array. Here is my code for the comparison: for ( int j = 0 ; j < wordCount ; j++) { for (int i = wordCount-1 ; i > j ; i--) { if (stringArray[i].compareTo(stringArray[j]) == 0 && i!=j) { //duplicate duplicates++; } } } wordCount -= duplicates; System.out.print("\nNumber of words, not including duplicates: " + wordCount); in the if statement, it says NullPointerException . What does this mean? Is there a better way to do this? I tried simply

NullPointerException when trying to use image resource

一世执手 提交于 2019-12-19 10:48:19
问题 I made a game in Java. It works completly fine in Eclipse. I exported it as a Runnable JAR. When double-clicking on it's icon, it doesn't open. So I tried running the JAR from the command line. I get a NullPointerException error, in a line of code that's trying to retrieve an image resource (as I said, it works fine inside Eclipse). This is the line of code where the error happens: ball = new ImageIcon(this.getClass().getResource("sprites/ball.PNG")); I have no idea what's wrong. Here is the

java.lang.NullPointerException when running testcase via Selenium

試著忘記壹切 提交于 2019-12-19 10:33:15
问题 I am facing an issue with NullPointerException. I tried as much as possible but I'm unable to resolve this. I am implementing a POM model(Selenium) for my project. The page: public class VendorsHomePageApp { WebDriver driver; public VendorsHomePageApp(WebDriver driver) { this.driver=driver; } @FindBy(how=How.XPATH,using=".//*[@id='navbarCollapse']/ul[1]/li[1]/a") WebElement dashboardTab; @FindBy(how=How.XPATH,using=".//*[@id='navbarCollapse']/ul[1]/li[2]/a") WebElement tendersTab; @FindBy(how

Null Pointer Exception In Fragments

白昼怎懂夜的黑 提交于 2019-12-19 08:07:14
问题 I am getting NullPointerException while Starting One Fragment From other Fragment. I am trying to call a method in the second Fragment after Starting the Fragment dynamically. Here is my logcat: 05-20 09:58:31.907: E/AndroidRuntime(2585): FATAL EXCEPTION: main 05-20 09:58:31.907: E/AndroidRuntime(2585): java.lang.NullPointerException 05-20 09:58:31.907: E/AndroidRuntime(2585): at com.exercise.FragmentTest.MyFragment3.setImage(MyFragment3.java:22) 05-20 09:58:31.907: E/AndroidRuntime(2585): at

findViewById() may produce NullPointerException

瘦欲@ 提交于 2019-12-19 06:53:44
问题 I have many of these calls: (ListView) getView().findViewById(R.id.main_list_view); (TextView) getView().findViewById(R.id.items_no); .... and AndroidStudio tells me that they may procude a NullPointerException : Method invocation getView().findViewById(R.id.main_list_view) may produce java.lang.NullPointerException less... (Ctrl+F1) This inspection analyzes method control and data flow to report possible conditions that are always true or false, expressions whose value is statically proven

Convert null object to String

微笑、不失礼 提交于 2019-12-19 05:28:29
问题 I have written an android program to load values to tablerow from web service. But a value comes null so I need do convert it into string. Can some one tell me the method to do it. try{ SoapObject request = service.getRequest(); SoapSerializationEnvelope envelope = service.getEnvelope(request); SoapObject response = service.getResponse(envelope); Log.i("Service Master", response.toString()); int count = response.getPropertyCount(); for (int i = 0; i < count; i++) { SoapObject result =

Java NullPointerException on loading properties file

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 05:04:22
问题 public class SupplierCalculatorApplet extends JApplet{ ... public void init(){ loadProperties(); ... } ... private void loadProperties() { language = "en-us";//getParameter("Language"); prop = new Properties(); try { URL urlToProps = this.getClass().getResource("config/" + language + ".properties"); prop.load(urlToProps.openStream());//Exception Caught Here } catch (IOException e) { } } Exception is found at the line indicated above. Whether language is a valid properties file or not, I catch

Using data fetched in one Activity in another Activity

跟風遠走 提交于 2019-12-19 04:12:24
问题 I get certain data like say userName in Activity_1 from a web server. Then i want to use the same data in Activity_2 so i made this userName Public Static and used like this in Activity_2 Activity_1.userName But then when i am in Activity_2 and press Home Button and reopen the application 5 mins later, this Activity_1.userName become Null since that Activity_1 data is destroyed . and I get NullPointerException How to solve this in a simple way. I just gave an example of userName but actually

null pointer exception apache poi

核能气质少年 提交于 2019-12-18 21:53:40
问题 hi we've been reading xls and xlsx file using apache poi ing our java program, the problem is we are getting null pointer exception with two reasons.. the first 1 is the blank cell which we already solved and the other one is when we are choosing a certain column that doesn't have any record.. our program ask for the path of the excel file then the specific sheet number of the file and the specific column number of the sheet you want to read.. here is the code for reading xls file public void

java.lang.NullPointerException: Attempt to invoke virtual method on a null object reference to select sqlite

淺唱寂寞╮ 提交于 2019-12-18 13:29:23
问题 I am a newbie of android world. I have a problem of the coding. It was just a tiny error buy i dont know it doesnt work even i change others method but the error still the same error. Here the error occur at logcat: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor com.example.zellon.surveyapps.DatabaseHelper.getAData()' on a null object reference I just want to select the data in the database to get an id but cant cuz of the error above. I will give a