我正在使用sharingIntent
分享应用上的链接。当我单击按钮时,它会带来共享窗口,我正确地共享链接。之后,共享过程,我的应用程序没有打开和崩溃。我正在使用intent.getExtras()
来识别图像和图像。 Logcat说问题是数组索引是11,大小等于零。但是,我不知道如何解决它。
在共享流程完成后,此行会出错:imageLoader.displayImage(imageUrls.get(imagePosition), imageView);
这是我的活动:
public class ProductDetail extends Activity {
static List<String> imageUrls = Data.BIGIMAGE;
static List<String> productUrl = Data.PRODUCT_URL;
DisplayImageOptions options;
LinearLayout shareButton;
int imagePosition;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.single_itemview);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if(bundle!=null){
imagePosition = bundle.getInt("imagePosition");
}
ImageView imageView = (ImageView) findViewById(R.id.pager);
shareButton = (LinearLayout)findViewById(R.id.btn_share);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(imageUrls.get(imagePosition), imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ProductDetail.this, WebViewActivity.class);
i.putExtra("productUrl", productUrl.get(imagePosition));
startActivity(i);
}
});
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, productUrl.get(imagePosition));
startActivity(Intent.createChooser(sharingIntent,"Share With?"));
}
});
}
}
和logcat输出:
02-12 10:53:45.405: E/AndroidRuntime(31742): FATAL EXCEPTION: main
02-12 10:53:45.405: E/AndroidRuntime(31742): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.ProductDetail}: java.lang.IndexOutOfBoundsException: Invalid index 11, size is 0
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.ActivityThread.access$700(ActivityThread.java:159)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.os.Looper.loop(Looper.java:176)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.ActivityThread.main(ActivityThread.java:5419)
02-12 10:53:45.405: E/AndroidRuntime(31742): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 10:53:45.405: E/AndroidRuntime(31742): at java.lang.reflect.Method.invoke(Method.java:525)
02-12 10:53:45.405: E/AndroidRuntime(31742): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-12 10:53:45.405: E/AndroidRuntime(31742): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-12 10:53:45.405: E/AndroidRuntime(31742): at dalvik.system.NativeStart.main(Native Method)
02-12 10:53:45.405: E/AndroidRuntime(31742): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 11, size is 0
02-12 10:53:45.405: E/AndroidRuntime(31742): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
02-12 10:53:45.405: E/AndroidRuntime(31742): at java.util.ArrayList.get(ArrayList.java:308)
02-12 10:53:45.405: E/AndroidRuntime(31742): at com.example.ProductDetail.onCreate(ProductDetail.java:39)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.Activity.performCreate(Activity.java:5372)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
02-12 10:53:45.405: E/AndroidRuntime(31742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
答案 0 :(得分:1)
Data.BIGIMAGE
显然是空的。要证明这取代了这一行
imageLoader.displayImage(imageUrls.get(imagePosition), imageView);
用这个
if (Data.BIGIMAGE != null && Data.BIGIMAGE.size() > 0) {
imageLoader.displayImage(Data.BIGIMAGE.get(imagePosition), imageView);
} else {
Log.e(getClass().getSimpleName(), "Data.BIGIMAGE is null or empty");
}