Android Studio Intent.putExtra Error - android

Intent.putExtra Error
I have no idea whats happening in my program.
I've tried parcelable, serializable, CharSequence & String.valueOf to avoid the error but it crash when I debuging run this line every time.
I check out most tutorial using same method but no error founded, What is the problem and how can I fix this.
Thank you.

object can't be put in extras directly it have to serialize then pass to intend
you can use this
https://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/

Related

Error while trying to use .startsWith() and .contains() methods in kotlin

When I try to use the methods .startsWith and .contains with the variable value, I get the words in red, because apparently, they do not exist.
Can someone help with this error? I tried looking on the internet to see if this is an old deprecated function but I did not find anything apparently it is not deprecated...
Click to see the error here
I think you are leaving an space after calling the contains function. So is like you are not sending any arguments to the function.
It should be like this:
value.contains("/")
And same for startsWith
value.startsWith("-")
I just updated my old Android studio from 4.1.2 to the new ARTIC FOX 2020.3.1... and the error magically disappeared...Thanks.

Unable to passing value to another activity in Android

I want to sent value to another activity. I'm using VS 2012 C# for developing apps. I have done lot of search from google. I have tried almost every methods. in my application getIntent(); giving error. that is, getIntent() does not exist in the current context.
I'm also not getting these below functions in my application.
Intent sender=getIntent();
getApplicationContext();
I have added all references. Help me where Am I wrong?
I got answer, I have to use below line of for getting value:
string extraData = Intent.GetStringExtra("KeyName");

if statement crashing my Android application

I need help with using an if statement in java, here is my code :
if(ans==1)
{
txtans.setText("This is a Prime Number");
}
else
{
txtans.setText("This is NOT a Prime Number");
}
if I remove the setText methods in both statements my program works, but when I leave them there and the program finds ans, then it quits, I'm wondering whats wrong with the statements? or is it not possible to use the setText method within if statements..if so how do I overcome this? What I want to do is print a string to the TextView layout when the ans = 1, any suggestions?
Yes, you can run txtans.setText() in an if statement just as well as you could run it if it wasn't in an if statement. You likely just don't have txtans initialised properly.
A quick google search brought up this as a way to print text to a textview.
Check your code, this erros usually comes when use findViewById() method in a wrong view.
In the activity you use like this findViewById(), maybe you need to call yourView.findViewById();
(If you post your class we can help you with more detailed answear.)
Also note that it is not allowed to call methods from Views from another Thread which created them. But a LogCat output including the Error will enlight us for shure :)
txtans might be NULL and you are trying to access a member of a NULL object.

Passing String array using intent

i am struck with passing String array from one activity to another using intent. while passing only a String from two activities, its work clear. but whenever i tried to access string array i am getting force close error. can any one guide me to rectify the problem.
You can use just the Intent.setExtra(String, Serializable) method. It accepts any Serializable object. If that does not work, please attach results from your LogCat, "Closed unexpectedly" just means your app failed, LogCat tells why it failed.
use Parcelable to do this.
please refer to this link http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/

android ProgressDialog - needs onClickListener?

I am trying to use the help example of ProgressDialog.show(Context, message, message, boolean).
Target Android 2.1 level 7 and using Eclipse.
The code is refused with message that new View.onClickListener is the first parameter.
I cant find any reference or example of this form in the Android developer help or by googling. Can anyone help please?
Ron
It's hard to tell without seeing your code, but it sounds to me that you might be trying to use "this" as a reference to the context as the first parameter, and that you're inside the onClickListener when you're doing it. While in there, "this" doesn't refer to your Activity, but to your OnClickListener. Try saving a reference to your context in the activity's onCreate method and using that as the parameter for the ProgressDialog.show call.

Categories

Resources