-1

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

这是我如何放置额外内容:

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
4

3 回答 3

1
  i.putExtra(hoteli.get(position).getImage(), "listing_image");

第一个参数是键而不是值:

  i.putExtra("listing_image", hoteli.get(position).getImage());

此外,由于您没有使用捆绑包来放置您的 listener_image,而是将其嵌入到 Intent 中,因此您应该以这种方式检索它:

String imgURL = getIntent(). getStringExtra("listing_image");
于 2013-06-02T13:56:33.127 回答
1
 Intent i = new Intent(Hoteli.this, ListingDetails.class);
            i.putExtra(hoteli.get(position).getImage(), "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 
}  
于 2013-06-02T13:58:39.253 回答
0

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

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

               i.putExtra("listing_image",hoteli.get(position).getImage() );
于 2013-06-02T13:56:25.067 回答