nullpointerexception

java.lang.NullPointerException with android fragment

感情迁移 提交于 2020-01-14 03:29:31
问题 I am trying to implement Fragments in my application. The problem occurs when I change tabs (I'm using drawer layout), I get a java.lang.NullPointerException error. I tested the code on the main activity and it worked smoothly. the only problem is when I apply it on fragment. here is the code: import android.app.Fragment; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import

Null pointer Exception: GestureDetector.onTouchEvent for custom gallery in android for ICS 4.0

試著忘記壹切 提交于 2020-01-13 17:07:28
问题 In one of my android app, I am using custom gallery to show images in gallery . (I am using custom gallery in order to show 1 item a time when swapping the gallery) Here is the code that I am using for custom gallery : public class CustomGallery extends Gallery { public CustomGallery(Context context) { super(context); } public CustomGallery(Context context, AttributeSet attrs) { super(context, attrs); } public CustomGallery(Context context, AttributeSet attrs, int defStyle) { super(context,

android context nullpointerexception

≯℡__Kan透↙ 提交于 2020-01-13 14:58:11
问题 I have a little issue with android Context and I don't know how to solve the problem.Here is the code I am using : public class TestActivity { Context context; public static String getPackageVersion(){ try { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0); version = packageInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return version; } public static boolean checkClientApiVer(String

Null pointer access: The variable can only be null at this location

让人想犯罪 __ 提交于 2020-01-13 03:53:09
问题 for(int i=0;i<n;i++){ for(int j=0;j<26;j++){ if(str.charAt(i)== strChar.charAt(j) ) * strSet1.append(str.charAt(i)); } * strSet2.append(str.charAt(i)); } Exception: Exception in thread "main" java.lang.NullPointerException at AterSeries.main(AterSeries.java:33) why this code gives null pointer exception warning: Null pointer access: The variable strSet1 can only be null at this location Null pointer access: The variable strSet2 can only be null at this location 回答1: Are strSet1 and strSet2

java.lang.RuntimeException: Failure delivering result ResultInfo while logging using Facebook

流过昼夜 提交于 2020-01-12 19:08:15
问题 My application is working fine on emulator. So I decided to run my application on my Android phone. I am trying to login to Facebook account using my application and it works fine on emulator. And as soon as I run my application on android phone I always get this exception- 01-30 11:06:08.400: E/AndroidRuntime(7463): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {com.facebook.samples.sessionlogin/com.facebook

Should I throw a NullPointerException explicitly or let Java do it for me?

让人想犯罪 __ 提交于 2020-01-12 14:00:34
问题 As the title says, I am wondering what the best practice is regarding the throwing of NullPointerExceptions. Specifically, if I have an external library function that can return null in circumstances that I don't want to actually handle (see below for a specific example), as the null indicates a problem with the software. The question is, should I check the return value for null and throw the NullPointerException myself, or should I just let Java do the dirty work for me as soon as I try to

Should I throw a NullPointerException explicitly or let Java do it for me?

此生再无相见时 提交于 2020-01-12 14:00:33
问题 As the title says, I am wondering what the best practice is regarding the throwing of NullPointerExceptions. Specifically, if I have an external library function that can return null in circumstances that I don't want to actually handle (see below for a specific example), as the null indicates a problem with the software. The question is, should I check the return value for null and throw the NullPointerException myself, or should I just let Java do the dirty work for me as soon as I try to

NullPointerException with static variables

北城余情 提交于 2020-01-12 08:05:51
问题 I just hit very strange (to me) behaviour of java. I have following classes: public abstract class Unit { public static final Unit KM = KMUnit.INSTANCE; public static final Unit METERS = MeterUnit.INSTANCE; protected Unit() { } public abstract double getValueInUnit(double value, Unit unit); protected abstract double getValueInMeters(double value); } And: public class KMUnit extends Unit { public static final Unit INSTANCE = new KMUnit(); private KMUnit() { } //here are abstract methods

NullPointerException with static variables

孤街醉人 提交于 2020-01-12 08:05:44
问题 I just hit very strange (to me) behaviour of java. I have following classes: public abstract class Unit { public static final Unit KM = KMUnit.INSTANCE; public static final Unit METERS = MeterUnit.INSTANCE; protected Unit() { } public abstract double getValueInUnit(double value, Unit unit); protected abstract double getValueInMeters(double value); } And: public class KMUnit extends Unit { public static final Unit INSTANCE = new KMUnit(); private KMUnit() { } //here are abstract methods

NullPointerException with static variables

假如想象 提交于 2020-01-12 08:05:26
问题 I just hit very strange (to me) behaviour of java. I have following classes: public abstract class Unit { public static final Unit KM = KMUnit.INSTANCE; public static final Unit METERS = MeterUnit.INSTANCE; protected Unit() { } public abstract double getValueInUnit(double value, Unit unit); protected abstract double getValueInMeters(double value); } And: public class KMUnit extends Unit { public static final Unit INSTANCE = new KMUnit(); private KMUnit() { } //here are abstract methods