Ok, first of all, I know what is NullPointer but wanted to ask what could cause such a behaviour.
I received crash on Crittercism and stacktrace is pointing to List.add:
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.xxx.android.activities.SuperActivity.onCreate(SourceFile:59)
at com.xxx.android.activities.XXXActivity.onCreate(SourceFile:30)
But the fact is that there is no list in onCreate or even the whole SuperActivity.
What could cause such a stacktrace in Android? How can I find this NullPointer or similar source?
EDIT
As per request SuperActivity code around line 59:
super.onCreate(savedInstanceState);
if (activitiesCreated == 0) {
isFirstStart = true;
}
activitiesCreated++;
EDIT 2
I know how to follow stacktrace. What I want to know is what could be the problem and what can I do in cases like this?
EDIT 3
Stacktrace for the crashing thread:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.android/com.xxx.android.activities.XXXActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.xxx.android.activities.SuperActivity.onCreate(SourceFile:59)
at com.xxx.android.activities.XXXActivity.onCreate(SourceFile:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
... 9 more
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.xxx.android.activities.SuperActivity.onCreate(SourceFile:59)
at com.xxx.android.activities.XXXActivity.onCreate(SourceFile:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Related
I'm working with a list:
List<Float> subjects = Arrays.asList(0f,0f,0f,0f,0f,0f);
List<Float> question9 = Arrays.asList(0f,0f);
And I want to put send it to another activity using Intent like this:
Intent iQuizz= new Intent(BachelorsResults.this, Results.class);
iQuizz.putExtra(BACHELOR, spinner.getSelectedItem().toString());
iQuizz.putExtra(QUESTION_9, question9.toArray());
iQuizz.putExtra(FAILED_SUBJECTS, subjects.toArray());
BachelorsResults.this.startActivity(iQuizz);
In the another activity I'm trying to receive float values:
Bundle extras = getIntent().getExtras();
float[] q9= extras.getFloatArray(QUESTION_9);
float[] fSubjects= extras.getFloatArray(FAILED_SUBJECTS);
But once I start this second activiy it launchs this Exception:
3-05 15:30:28.221 24640-24640/citrapp.exatec E/AndroidRuntime: FATAL EXCEPTION: main
Process: citrapp.exatec, PID: 24640
java.lang.RuntimeException: Unable to start activity ComponentInfo{citrapp.exatec/citrapp.exatec.Resultados}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at citrapp.exatec.Resultados.onCreate(Resultados.java:85)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Somehow when I pass them to the another activity, float arrays become nulls, because I test extras.getFloatArray inside the first activity and it shows the content, but in the second activity it doesn't. If somebody could help me would be awesome..
Thanks!
Try replacing getIntent().getExtras() with getIntent().getFloatArrayExtra().
I have encountered a problem in which when ever I use
final MediaPlayer tick = MediaPlayer.create(getApplicationContext(), R.raw.tick);
tick.start();// tick is a short .mp3 file
in my app, no matter where, I get:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
at com.a.aar.MainActivity.onClicks(MainActivity.java:123)
at com.a.aar.MainActivity$2.onClick(MainActivity.java:97)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
But, whenever I use a slightly shorter sound effect, the app runs great.(I need a short sound because I want a lot of sounds coming fast and so the sounds will not stop)
What is the reason to this error and how can I solve it?
I am new to openCV and android. I am trying to load an image from Resources using bitmap and process the image using open CV. It gave me this error:
java.lang.NullPointerException:
Attempt to read from field 'long org.opencv.core.Mat.nativeObj' on a null object reference
Code:
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.a1);
((ImageView)findViewById(R.id.imageView)).setImageBitmap(bm);
Mat trainImage = new Mat(bm.getHeight(),bm.getWidth(),CvType.CV_32S);
Utils.bitmapToMat(bm,trainImage);
if(trainImage.empty()){
Log.e(TAG,"Empty image");
}
else{
Log.e(TAG,"Image Loaded");
}
Imgproc.cvtColor(trainImage, trainGray, Imgproc.COLOR_RGBA2GRAY);
Here is the Exception message:
E/SVM: Image Loaded
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pragyan.facefeatures, PID: 3308
java.lang.NullPointerException: Attempt to read from field 'long org.opencv.core.Mat.nativeObj' on a null object reference
at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:1724)
at com.example.pragyan.facefeatures.ExtractFeature.trainSvm(ExtractFeature.java:242)
at com.example.pragyan.facefeatures.ExtractFeature.onOptionsItemSelected(ExtractFeature.java:313)
at android.app.Activity.onMenuItemSelected(Activity.java:2885)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:403)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:189)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:663)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
at android.support.v7.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:191)
at android.widget.AdapterView.performItemClick(AdapterView.java:305)
at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3053)
at android.widget.AbsListView$3.run(AbsListView.java:3860)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Can anyone tell me how to fix this. The image is loaded successfully and it still gives a NullPointerException.
I think you've not initialized the Mat trainGray. Try the following.
Mat trainGray = new Mat();
Imgproc.cvtColor(trainImage, trainGray, Imgproc.COLOR_RGBA2GRAY);
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
i'm implementing google maps in an android project . But as soon as i moved my project into another PC machine i'm facing app crashs and this error message in my logcat console :
FATAL EXCEPTION: main
Process: com.egsdigital.dolan, PID: 24887
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.egsdigital.dolan/com.egsdigital.dolan.Activities.MainPage_Pasenger}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setOnCameraChangeListener(com.google.android.gms.maps.GoogleMap$OnCameraChangeListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setOnCameraChangeListener(com.google.android.gms.maps.GoogleMap$OnCameraChangeListener)' on a null object reference
at com.egsdigital.dolan.Activities.MainPage_Pasenger.onCreate(MainPage_Pasenger.java:178)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
and here where the error points on:
map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition position) {
LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
mAdapter.setBounds(bounds);
}
});
thanks so much.
you must add new SHA1 into google console.
See this link for fetch SHA1 from your OS : How to get the SHA1 fingerprint certificate in android studio for debug mode
After fetching your SHA1 code, insert into console.developers and running Application .
Hope help you
My app crashes on a NPE even though i'm checking whether the value of the String is non null:
if (AppConstants.AppConstants_appName != null &&
AppConstants.AppConstants_appName.equals("xxx")) {
suffix = "version=1.0";
}
AppConstants_appName is a public static String.
Not sure what's going wrong here.
Here's my Stacktrace. Anyone an idea?
Stacktrace
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at nl.onlineretailservice.library.APIManager.getURLSuffix(APIManager.java:637)
at nl.onlineretailservice.library.APIManager.requestFolderProducts(APIManager.java:334)
at nl.onlineretailservice.helper.FolderViewerActivityHelper.loadProducts(FolderViewerActivityHelper.java:160)
at nl.onlineretailservice.helper.FolderViewerActivityHelper$2.downloadReady(FolderViewerActivityHelper.java:267)
at nl.onlineretailservice.library.DownloadOperation.onPostExecute(DownloadOperation.java:221)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)