某些可可足类,例如YLTableView,请勿将tabian.com.hash E/AndroidRuntime: FATAL EXCEPTION: main
Process: tabian.com.hash, PID: 29587
java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at tabian.com.hash.Share.GalleryFragment.setupGridView(GalleryFragment.java:159)
at tabian.com.hash.Share.GalleryFragment.access$300(GalleryFragment.java:38)
at tabian.com.hash.Share.GalleryFragment$3.onItemSelected(GalleryFragment.java:134)
设置为其public class GalleryFragment extends Fragment {
private static final String TAG = "GalleryFragment";
//constants
private static final int NUM_GRID_COLUMNS = 3;
//widgets
private GridView gridView;
private ImageView galleryImage;
private ProgressBar mProgressBar;
private Spinner directorySpinner;
//vars
private ArrayList<String> directories;
private String mAppend = "file:/";
private String mSelectedImage;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_gallery, container, false);
galleryImage = view.findViewById(R.id.galleryImageView);
gridView = view.findViewById(R.id.gridView);
directorySpinner = view.findViewById(R.id.spinnerDirectory);
mProgressBar = view.findViewById(R.id.progressBar);
mProgressBar.setVisibility(View.GONE);
directories = new ArrayList<>();
Log.d(TAG, "onCreateView: started.");
ImageView shareClose = view.findViewById(R.id.ivCloseShare);
shareClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: closing the gallery fragment.");
Objects.requireNonNull(getActivity()).finish();
}
});
TextView nextScreen = view.findViewById(R.id.tvNext);
nextScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: navigating to the final share screen.");
if(isRootTask()){
Intent intent = new Intent(getActivity(), NextActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
startActivity(intent);
}else{
Intent intent = new Intent(getActivity(), AccountSettingsActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
intent.putExtra(getString(R.string.return_to_fragment), getString(R.string.edit_profile_fragment));
startActivity(intent);
Objects.requireNonNull(getActivity()).finish();
}
}
});
init();
return view;
}
private boolean isRootTask(){
return ((ShareActivity) Objects.requireNonNull(getActivity())).getTask() == 0;
}
private void init(){
FilePaths filePaths = new FilePaths();
//check for other folders inside "/storage/emulated/0/pictures"
if (FileSearch.getDirectoryPaths(filePaths.PICTURES) != null) {
directories = FileSearch.getDirectoryPaths(filePaths.PICTURES);
}
directories.add(filePaths.CAMERA);
ArrayList<String> directoryNames = new ArrayList<>();
for (int i = 0; i < directories.size(); i++) {
Log.d(TAG, "init: directory: " + directories.get(i));
int index = directories.get(i).lastIndexOf("/");
String string = directories.get(i).substring(index);
directoryNames.add(string);
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(getActivity()),
android.R.layout.simple_spinner_item, directoryNames);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
directorySpinner.setAdapter(adapter);
directorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick: selected: " + directories.get(position));
//setup our image grid for the directory chosen
setupGridView(directories.get(position));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
private void setupGridView(String selectedDirectory){
Log.d(TAG, "setupGridView: directory chosen: " + selectedDirectory);
final ArrayList<String> imgURLs = FileSearch.getFilePaths(selectedDirectory);
//set the grid column width
int gridWidth = getResources().getDisplayMetrics().widthPixels;
int imageWidth = gridWidth/NUM_GRID_COLUMNS;
gridView.setColumnWidth(imageWidth);
//use the grid adapter to adapter the images to gridview
GridImageAdapter adapter = new GridImageAdapter(getActivity(), R.layout.layout_grid_imageview, mAppend, imgURLs);
gridView.setAdapter(adapter);
//set the first image to be displayed when the activity fragment view is inflated
try{
setImage(imgURLs.get(1), galleryImage, mAppend);
mSelectedImage = imgURLs.get(1);
}catch (ArrayIndexOutOfBoundsException e){
Log.e(TAG, "setupGridView: ArrayIndexOutOfBoundsException: " +e.getMessage() );
}
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick: selected an image: " + imgURLs.get(position));
setImage(imgURLs.get(position), galleryImage, mAppend);
mSelectedImage = imgURLs.get(position);
}
});
}
private void setImage(String imgURL, ImageView image, String append){
Log.d(TAG, "setImage: setting image");
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(append + imgURL, image, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
mProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
mProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
mProgressBar.setVisibility(View.INVISIBLE);
}
});
}
}
的一部分。例如,这意味着'DEFINES_MODULE' => 'YES'
在Swift中不起作用,除非您像这样在Podfile中设置pod_target_xcconfig
:
import YLTableView
如果我正在编写podspec,是否有任何理由不应该像这样在我的配置中包括DEFINES_MODULE?
:modular_headers => true
在我看来,这没有任何负面影响,它使Swift用户可以更轻松地使用我的库。
答案 0 :(得分:3)
存在一个已知问题(具有解决方法):https://github.com/CocoaPods/CocoaPods/issues/7584。这可能会导致用户直接在其预编译头(* .pch)中导入Objective-C lib头的问题。您可以通过在lib源文件中包含一个空的swift文件来解决此问题。在将来的CocoaPods版本中,可能会有一个干净的修复程序。
否则,没有实际的负面影响。它可以在构建时为导入提供更严格的搜索路径,这意味着:
@import
或在Swift中使用import
找到它)来自the blog post regarding CocoaPods 1.5.0 release:
[...] CocoaPods允许任何Pod导入具有未命名的引号导入的任何其他Pod。
例如,容器B可能具有带有#import“ A.h”语句的代码,并且CocoaPods将创建构建设置,该设置将允许此类导入成功。但是,如果尝试将模块映射添加到这些容器中,则此类导入将无法进行。多年前,我们试图为静态库自动生成模块映射,但由于它破坏了一些吊舱,因此我们不得不还原。
在此版本中,您将可以选择更严格的标头搜索路径(以及为Objective-C Pod生成模块映射)。作为Pod作者,您可以在pod_target_xcconfig中添加'DEFINES_MODULE'=>'YES'。 [...]