应用程序崩溃而不显示错误(FragmentPagerAdapter)

时间:2017-05-14 17:58:47

标签: android android-fragments fragmentpageradapter android-pageradapter

我的CarouselPagerAdapter扩展了FragmentPagerAdapter。 我的主管负责在应用程序中添加另一个选项卡(这是一个片段)。

我一直试图在CarouselPagerAdapter中添加单个片段,但我的应用会立即崩溃而不会显示错误。

即使是最简单的克隆另一个片段,但更改片段的名称仍会导致应用崩溃。我不知道这个应用程序的逻辑,我真的很沮丧。我希望你们能弄明白什么是错的。

这是CarouselPagerAdapter

的一部分
public class CarouselPagerAdapter extends FragmentPagerAdapter {

private final Resources resources;

/**
 * Create pager adapter
 *
 * @param resources
 * @param fragmentManager
 */
List<FragmentGenerate> list=new ArrayList<FragmentGenerate>();
public CarouselPagerAdapter(final Resources resources, final FragmentManager fragmentManager) {
    super(fragmentManager);
    this.resources = resources;


    //Newly added tab

    list.add(new FragmentGenerate() {
        @Override
        public ContactFragment newInstance() {
            return ContactFragment.newInstance();
        }

        @Override
        public String instanceName() {
            return "Retrofit Sample";
        }
    });
    //END

这是我尝试克隆的标签MoviesFragment

public class MoviesFragment extends BaseFragment {

@Inject
protected MovieService movieService;

@InjectView(R.id.lvListHolder)
protected ListView lvMovies;


@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Injector.inject(this);
}
@Override
public View onCreateView2(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_simplelist, container, false);
}

@Override
public void onActivityCreated2(Bundle savedInstanceState) {
    MovieAdapter adapter=new MovieAdapter(getActivity(),movieService);
    lvMovies.setAdapter(adapter);
    lvMovies.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Movie movie=(Movie)adapterView.getItemAtPosition(i);
            MovieActivity.start(getActivity(), movie);
        }
    });
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){}

//Here you Save your data
@Override
public void onSaveInstanceState2(Bundle outState) {}


public static MoviesFragment newInstance(){
    return new MoviesFragment();
}

}

我克隆了它,只是更改了片段名称和实例名称,如下所示:

public class ContactFragment extends BaseFragment



public static ContactFragment newInstance(){
    return new ContactFragment();
}

为什么会崩溃?它应该在逻辑上制作一个包含重复内容但名称不同的选项卡。不应该吗?请帮忙。

修改:  我修复了之前的错误,因为&#34;注入&#34;该模块,因为该应用程序使用Dagger Library。

问题:  我使用改造2库创建了一个应用程序,它的工作原理。当我尝试使用我的改装应用程序的内容添加片段时,方法getMyJSON()是(未知来源)

这是LOGCAT:

  

致命的例外:主要                                                                                               过程:securitywizards.herobo.com.androidtemplate,PID:11382                                                                                               java.lang.IllegalArgumentException:需要HTTP方法注释(例如,@ GET,@ POST等)。                                                                                                   方法RetrofitService.getMyJSON                                                                                                   at retrofit2.ServiceMethod $ Builder.methodError(ServiceMethod.java:695)                                                                                                   at retrofit2.ServiceMethod $ Builder.methodError(ServiceMethod.java:686)                                                                                                   at retrofit2.ServiceMethod $ Builder.build(ServiceMethod.java:173)                                                                                                   at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)                                                                                                   at retrofit2.Retrofit $ 1.invoke(Retrofit.java:145)                                                                                                   在java.lang.reflect.Proxy.invoke(Proxy.java:397)                                                                                                   在$ Proxy0.getMyJSON(未知来源)                                                                                                   at securitywizards.herobo.com.androidtemplate.viewcontroller.fragment.samples.ContactFragment.onCreate(ContactFragment.java:58)                                                                                                   在android.support.v4.app.Fragment.performCreate(Fragment.java:1763)                                                                                                   在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:913)                                                                                                   在android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:842)                                                                                                   在android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:859)                                                                                                   在android.support.v4.app.FragmentPagerAdapter.setPrimaryItem(FragmentPagerAdapter.java:130)                                                                                                   在android.support.v4.view.ViewPager.populate(ViewPager.java:1071)                                                                                                   在android.support.v4.view.ViewPager.populate(ViewPager.java:919)                                                                                                   在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.widget.LinearLayout.measureVertical(LinearLayout.java:963)                                                                                                   在android.widget.LinearLayout.onMeasure(LinearLayout.java:629)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.FrameLayout.onMeasure(FrameLayout.java:465)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.FrameLayout.onMeasure(FrameLayout.java:465)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)                                                                                                   在android.widget.LinearLayout.measureVertical(LinearLayout.java:760)                                                                                                   在android.widget.LinearLayout.onMeasure(LinearLayout.java:629)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.FrameLayout.onMeasure(FrameLayout.java:465)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.FrameLayout.onMeasure(FrameLayout.java:465)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.FrameLayout.onMeasure(FrameLayout.java:465)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)                                                                                                   在android.widget.LinearLayout.measureVertical(LinearLayout.java:760)                                                                                                   在android.widget.LinearLayout.onMeasure(LinearLayout.java:629)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)                                                                                                   在android.widget.FrameLayout.onMeasure(FrameLayout.java:465)                                                                                                   在com.android.internal.policy.impl.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2731)                                                                                                   在android.view.View.measure(View.java:17915)                                                                                                   在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2413)                                                                                                   在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1415)                                                                                                   在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1639)                                                                                                   在android.view.ViewR

ContactFragment:

public class ContactFragment extends BaseFragment {

private ListView listView;
private View parentView;

private ArrayList<Datum> datalist;
private ArrayList<Organization> datainfo;


private ContactAdapter adapter;



@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Injector.inject(this);
    RetrofitService api = Client.getApiService();

    Call<Util> call = api.getMyJSON();

    call.enqueue(new Callback<Util>() {
        @Override
        public void onResponse(Call<Util> call, Response<Util> response) {
            //Dismiss Dialog


            if (response.isSuccessful()) {

                datalist = response.body().getOrganization().getData();

                adapter = new ContactAdapter(getActivity(), datalist);
                listView.setAdapter(adapter);

            } else {
                Toast.makeText(getActivity(), "error", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Call<Util> call, Throwable t) {
            Toast.makeText(getActivity(), "error", Toast.LENGTH_SHORT).show();
        }
    });
}
@Override
public View onCreateView2(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_simplelist, container, false);
    listView = (ListView) view.findViewById(R.id.lvListHolder);
    datalist = new ArrayList<Datum>();

    return view;
}

@Override
public void onActivityCreated2(Bundle savedInstanceState) {

    //Creating an object of our api interface

}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){}

//Here you Save your data
@Override
public void onSaveInstanceState2(Bundle outState) {}


public static ContactFragment newInstance(){
    return new ContactFragment();
}

}

这是具有getMyJSON方法的接口:

public interface RetrofitService {

public static final String URL_GETLIST ="api/organizations?type=json";

@GET(URL_GETLIST)
Call<Util> getMyJSON();

}

我已经包含了该模块中的所有课程:

@Module(
    complete = false,

    injects = {
            MainApplication.class
            ,NavigationDrawerFragment.class
            , BaseFragment.class
            , CarouselFragment.class
            , SimpleFragment.class
            , SimpleListFragment.class
            , MoviesFragment.class
            , ButtonFragment.class
            , ProgressFragment.class
            , DownloadService.class
            , MainActivity.class
            , ParallaxFragment.class
            , SwipeFragment.class
            , DaimajaSliderFragment.class
            , DatabaseListFragment.class
            , ContactFragment.class
            , MovieActivity.class
            , SweetDialogFragment.class
            , ListViewParallaxFragment.class
            , SimpleWebViewFragment.class
            , Client.class
            , Util.class  //1st Class
            , Datum.class //2nd Class
            , Organization.class //3rd Class

    }

0 个答案:

没有答案