Android 无法获取字符串附加值

Android 无法获取字符串附加值,android,android-activity,Android,Android Activity,我想得到一个额外的字符串,但我得到了这个错误,我无法找出问题出在哪里: 以下是我如何放置额外的内容: Intent i = new Intent(Hoteli.this, ListingDetails.class); i.putExtra(hoteli.get(position).getImage(), "listing_image"); Bundle extras = getIntent().getExtras(); String imgURL=extras.getString("listi

我想得到一个额外的字符串,但我得到了这个错误,我无法找出问题出在哪里:

以下是我如何放置额外的内容:

Intent i = new Intent(Hoteli.this, ListingDetails.class);
i.putExtra(hoteli.get(position).getImage(), "listing_image");
Bundle extras = getIntent().getExtras();
String imgURL=extras.getString("listing_image");
Log.v("--", imgURL);
我是如何得到额外的东西的:

Intent i = new Intent(Hoteli.this, ListingDetails.class);
i.putExtra(hoteli.get(position).getImage(), "listing_image");
Bundle extras = getIntent().getExtras();
String imgURL=extras.getString("listing_image");
Log.v("--", imgURL);
这是我的LogCat输出:

06-02 13:51:27.561: E/AndroidRuntime(535): FATAL EXCEPTION: main
06-02 13:51:27.561: E/AndroidRuntime(535): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.biznismap.com/com.biznismap.com.activities.ListingDetails}: java.lang.NullPointerException: println needs a message
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.os.Looper.loop(Looper.java:123)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 13:51:27.561: E/AndroidRuntime(535):  at java.lang.reflect.Method.invokeNative(Native Method)
06-02 13:51:27.561: E/AndroidRuntime(535):  at java.lang.reflect.Method.invoke(Method.java:521)
06-02 13:51:27.561: E/AndroidRuntime(535):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-02 13:51:27.561: E/AndroidRuntime(535):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-02 13:51:27.561: E/AndroidRuntime(535):  at dalvik.system.NativeStart.main(Native Method)
06-02 13:51:27.561: E/AndroidRuntime(535): Caused by: java.lang.NullPointerException: println needs a message
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.util.Log.println_native(Native Method)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.util.Log.v(Log.java:101)
06-02 13:51:27.561: E/AndroidRuntime(535):  at com.biznismap.com.activities.ListingDetails.getExtras(ListingDetails.java:34)
06-02 13:51:27.561: E/AndroidRuntime(535):  at com.biznismap.com.activities.ListingDetails.init(ListingDetails.java:51)
06-02 13:51:27.561: E/AndroidRuntime(535):  at com.biznismap.com.activities.ListingDetails.onCreate(ListingDetails.java:28)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-02 13:51:27.561: E/AndroidRuntime(535):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-02 13:51:27.561: E/AndroidRuntime(535):  ... 11 more

您在put extra方法中给出了错误的键和带有值的值更改键

              i.putExtra("KEY","Value");

               i.putExtra("listing_image",hoteli.get(position).getImage() );
第一个参数是键而不是值:

  i.putExtra("listing_image", hoteli.get(position).getImage());
此外,由于您没有使用捆绑包来放置您的侦听图像,但您将其嵌入了Intent中,因此您应该通过以下方式检索它:

String imgURL = getIntent(). getStringExtra("listing_image");
应该是

 Intent i = new Intent(Hoteli.this, ListingDetails.class); 
 i.putExtra("listing_image", hoteli.get(position).getImage()); 
 //1st paramter is the key 
 //2nd parameter is the value
得到

 Bundle extras = getIntent().getExtras(); 
if (extras != null) {
String value = extras.getString("listing_image");
//get the value based on the key
// key should match 
}  

. 检查此链接。intent.putExtra(“key”,mystring);//参数1是键//参数2是值。要获取值,键应与String value=extras.getString(“键”)匹配;你能把打印行发出去吗?还是发布listingdetails java代码?