Click here to Skip to main content
15,609,550 members

Comments by David Crow (Top 200 by date)

David Crow 2 days ago View    
The code statement you've shown and the error you quote don't match. In other words, assigning a string literal to a string object will not cause such an error. You need to show the actual code snippet that causes the error.
David Crow 16-Mar-23 11:52am View    
"My problem is value passed by sharedpreferences is shown in new Mainactivity but it does not shows in open Mainactivity"

I'm confused. How can the value be shown but also not be shown?

Where in MainActivity are you retrieving the value from the login activity? In other words, from where are you calling getString() and setText()?

Have you considered using commit() rather than apply()?
David Crow 6-Mar-23 8:50am View    
There are three places where you are calling the append() method:
textViewCartData.append("Item: " + name + "");
itemWeight.append("Ceki: " + numItem + "");
itemPrice.append("" + price + "");
At least one of them is using a null object.
David Crow 8-Feb-23 8:27am View    
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.InputStream android.bluetooth.BluetoothSocket.getInputStream()' on a null object reference
at com.example.plavi_zub_2.MainActivity$SendReceive.<init>(MainActivity.java:331)


Look at line 331 of MainActivity.java. Do you see where the getInputStream() method is being called? Do you see the object it is being called from (bluetoothSocket)? It has a null value, which means the value being passed to the SendReceive constructor is also null (look at line 307 of MainActivity.java). That's your problem.

As an aside when posting, you should try and post only relevant code. Most of what you provided has nothing to do with the issue you're having.
David Crow 1-Feb-23 15:59pm View    
If you had an array of birthstones:
String[] stones = { "Garnet", "Amethyst", "Aquamarine", "Diamond" ... };
Then you would simply access that array using the month value:
stones[birthMonth - 1];