English 中文(简体)
意欲补外的例外情况
原标题:Exception while passing extras through intent

I want to pass a string from 1 activity to another, although I have taken reference from many accepted answers from other threads, I am facing problem that I am not able to debug. When I comment extras.putString as shown in code below, Toast message shows the correct address which means value is being set properly and code works fine but when I use extras.putString(), I get NullPointerException and application closes due to exception. There are many characters in my address string. Infact even if I use extras.putString("userAddress", "test") I get NullPointerException

在此,我的主要活动是我所说的“FBShare活动”:

Intent mIntent = new Intent(this, FBShare.class);   
Bundle extras = mIntent.getExtras();
String currentAddress = getCurrentAddress(ourLocation);
Toast.makeText(getBaseContext(), getCurrentAddress(ourLocation), Toast.LENGTH_SHORT).show();
extras.putString("userAddress", currentAddress);
startActivity(mIntent);

And in FBShare Activities 我试图 follows取以下价值观:

strAddress = getIntent().getExtras().getString("userAddress");  

这里指的是正在做类似事情的一条路。

最佳回答

尝试我的法典

Intent mIntent = new Intent(this, FBShare.class);   
Bundle extras = new Bundle();
String currentAddress = getCurrentAddress(ourLocation);
Toast.makeText(getBaseContext(), getCurrentAddress(ourLocation), Toast.LENGTH_SHORT).show();
extras.putString("userAddress", currentAddress);
mIntent.putExtras(extras);
startActivity(mIntent);

hope this will work.

问题回答

直接对意图进行补充:

mIntent.putExtra ("Key”,“Value”

另外,你还利用额外资金提取了这笔钱。

Intene t = getIntent();
String k="key";
if (t.hasExtra(k)) {
  s = t.getStringExtra(k);
  ...
}

很多种类的劳动力得到/投入

Intent mIntent = new Intent(this, FBShare.class);   
String currentAddress = getCurrentAddress(ourLocation);
Toast.makeText(getBaseContext(), getCurrentAddress(ourLocation), Toast.LENGTH_SHORT).show();
mIntent.putString("userAddress", currentAddress);
startActivity(mIntent);

就你而言,没有必要布局,因为你似乎只是用上面的法典来形容你。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签