Category : nullpointerexception

In my code I have been trying to get the location coordinates of the user using getLastKnownLocation() This method should only be called when mLocationPermissionGranted is set to true. After getting the location coordinates I store them in an object with the method createLocation which takes 2 doubles as parameters. However, before I can reach ..

Read more

arFragment.arSceneView returns null when I use view binding. The same code works while using kotlin synthetic plugin. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding= ActivitySceneFormBinding.inflate(layoutInflater) setContentView(binding.root) ModelRenderable.builder() .setSource(this, R.raw.sunglasses2) .build() .thenAccept { modelRenderable -> glasses.add(modelRenderable) modelRenderable.isShadowCaster = false modelRenderable.isShadowReceiver = false } val sceneView = arFragment.arSceneView sceneView.cameraStreamRenderPriority = Renderable.RENDER_PRIORITY_FIRST //scene view must not be ..

Read more

I am in a dilema. I have 10 functions each respectively initialises variables. The functions are called in a try-catch loop. The problem is that when any of those variables initialisations invokes a nullpointerexception then the entire try catch loop stops / breaks and all the other/following variables in and outside the function & other ..

Read more

Exception is: java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.widget.Button.setVisibility(int)’ on a null object reference I have a fragment with member variable which is Button and a getter: private Button mThrowButton; public Button getShowWordButton() { return mShowWordButton; } I initialize it in onCreateView method like so: View rootView = inflater.inflate(R.layout.fragment_throw_dice, container, false); mShowWordButton = rootView.findViewById(R.id.dice_after_throw_button); ..

Read more

I am developing MainContentPage in android studio in which i am working in Navigation View. My code is complete but i am getting Null Exception error in this line of code objectNavigationView.setNavigationItemSelectedListener(this); and in objectBottomNavigationView.setOnNavigationItemSelectedListener here is my complete java code public class MainContentPage extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { //Fragments Objects private TextThoughts objectTextThoughts; private ..

Read more

it is again a question about my first alarm program. Here is a snippet of my code. What I found out was that when I declare an object of type Alarm: Alarm alarm; inside the try{} statement, sometimes (not always!!) when I addressed that object several lines down (alarm.getId()) I got a null object addressing ..

Read more

I’m trying to make a CardView like the twitter ones to use it with a RecyclerView. The CardView without ImageView works well, but when I add ImageView the app gives me a NullPointerException This is the code of the CardView without the ImageView (Works well) : <?xml version="1.0" encoding="utf-8"?> <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/twoot_cardView" android:layout_width="match_parent" ..

Read more

I was following this tutorial: https://youtu.be/LyAmpfm4ndo to build an Android mobile chat app using Java. But when I try to run the code, this error java.lang.NullPointerException: Attempt to invoke virtual method ‘void androidx.appcompat.app.ActionBar.setTitle(java.lang.CharSequence)’ on a null object reference results. I have already checked my variable name(in the comment, it is suggested that some users may ..

Read more