我创建了3个片段java文件,并使用TabsPager文件来刷片段。现在我在StoreHomeFragment.java上添加了工作代码,添加到storehomefragment的代码是填充到gridview的集合
但现在我在TabsPager
中遇到错误TabsPagerAdapterStore.java
public class TabsPagerAdapterStore extends FragmentPagerAdapter {
public TabsPagerAdapterStore(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int index) {
switch (index) {
case 0: return new StoreGenreFragment();
case 1: return new StoreHomeFragment(); //this line error
case 2: return new StoreStepFragment();
}
return null;
}
@Override
public int getCount() {
// get item count - equal to number of tabs
return 3;
}}
在"案例1"弹出上面的错误。我使用右键单击和快速修复
Change method return type to StoreHomeFragment
我已经上传了图片,只是显示错误弹出,如果我选择那个,然后切换案例中的每个其他片段都会出错,请任何人帮我解决我可能犯的错误
StoreHomeFragment.java中存在的代码
public class StoreHomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.store_home, container, false);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
// Gridview
final GridView gridView1 = (GridView)rootView.findViewById(R.id.store_home_gridview);
String url = "http://192.168.1.132/Android/App/good.php";
try {
JSONArray data = new JSONArray(getJSONUrl(url));
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("name", c.getString("name"));
map.put("artist", c.getString("artist"));
map.put("price", c.getString("price"));
map.put("image", c.getString("image"));
MyArrList.add(map);
}
//gridView1.setAdapter(new ImageAdapter(this,MyArrList));
gridView1.setAdapter(new ImageAdapter(this,MyArrList));
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return rootView;
}
答案 0 :(得分:0)
检查StoreHomeFragment
是否扩展Fragment
,如果使用支持库,请检查类导入,因为Fragment
类也包含在支持库中。实际上,您必须导入在Fragment
或StoreGenreFragment
StoreStepFragment
课程