在调试模式下使用Retrofit回调时应用程序崩溃

时间:2016-02-26 16:52:29

标签: java android android-studio callback retrofit

当我尝试调试它时,我的应用程序崩溃,但在运行模式下运行正常。我查看了堆栈跟踪,我知道这是由于回调代码而发生的。

为什么应用程序仅在调试模式下崩溃?

这是片段:

public class MoviePosterFragment extends Fragment {

    private void updateMoviePosters(final RecyclerView rv) {
        MovieAPI mMovieAPI = NetworkAPI.createService(MovieAPI.class);
        Callback<movieGeneral> callback = new Callback<movieGeneral>()
        {
            @Override
            public void success(movieGeneral mMovieGeneral, Response response) {
                updateMovieGrid(rv, mMovieGeneral);
                Toast.makeText(getActivity(), "callback success!",
                        Toast.LENGTH_LONG).show();
            }
            @Override
            public void failure(RetrofitError error) {
                int a =0;
                //show error message
                //set adapter to null
                Toast.makeText(getActivity(), "fail!",
                        Toast.LENGTH_LONG).show();
            }
        };
        mMovieAPI.fetchPopMovies(MOST_POPULAR, API_KEY, callback);
    }
}

网络API:

public class NetworkAPI {

    //Volatile keyword ensures that multiple threads handle the     unique/instance correctly
    private volatile static NetworkAPI uniqueInstance;

    public static final String POP_MOVIES_URL = "http://api.themoviedb.org/3/discover/movie?";
    private final String API_KEY = "xxxxxxxxxxxxxxxxxxxxxx";

    final String SORT_PARAM = "sort_by";
    final String PAGE = "page";
    final String KEY = "api_key";

    private static RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(POP_MOVIES_URL) //API endpoint
            .setClient(new OkClient(new OkHttpClient())); //setClient: the HTTP client used for requests

    public static <S> S createService(Class<S> serviceClass) {
        RestAdapter adapter = builder.build();
        return adapter.create(serviceClass);
    }
}

接口:

public interface MovieAPI
    {

    @GET("/3/discover/movie")
    void fetchPopMovies
        (
        //@Query: specifies the query key name with the value of the annotated parameter.
        @Query("sort_by") String SORT_PARAM,
        @Query("api_key") String API_KEY,
        retrofit.Callback<movieGeneral> cb //last parameter must be a Callback so API call can run asynchronously
        );
    }

堆栈跟踪:

02-26 00:34:32.544 1109-1109/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
02-26 00:34:44.145 1109-1116/example.user.popmovie E/art: art::mirror::Object* art::StackVisitor::GetThisObject() const unimplemented Failed to determine this object of abstract or proxy method: void example.user.popmovie.utils.MovieAPI.fetchPopMovies(java.lang.String, java.lang.String, retrofit.Callback)  
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI GetStringUTFChars called with pending exception 'android.view.InflateException' thrown in android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean):548  
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]     in call to GetStringUTFChars  
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]     from int android.util.Log.println_native(int, int, java.lang.String, java.lang.String)  
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65] "main" prio=5 tid=1 Runnable
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   | group="main" sCount=0 dsCount=0 obj=0x8759bef0 self=0xb4f07800
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   | sysTid=1109 nice=0 cgrp=apps sched=0/0 handle=0xb6f67ec8
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   | state=R schedstat=( 0 0 0 ) utm=30 stm=10 core=2 HZ=100
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   | stack=0xbe4f4000-0xbe4f6000 stackSize=8MB
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   | held mutexes= "mutator lock"(shared held)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #00 pc 00004640  /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #01 pc 00002e8d  /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #02 pc 002481d1  /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+68)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #03 pc 0022cf0b  /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+146)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #04 pc 000b17ab  /system/lib/libart.so (art::JniAbort(char const*, char const*)+582)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #05 pc 000b1ee5  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #06 pc 000b4ff5  /system/lib/libart.so (art::ScopedCheck::ScopedCheck(_JNIEnv*, int, char const*)+1284)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #07 pc 000bce59  /system/lib/libart.so (art::CheckJNI::GetStringUTFChars(_JNIEnv*, _jstring*, unsigned char*)+24)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #08 pc 00062b75  /system/lib/libandroid_runtime.so (???)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #09 pc 00089511  /system/lib/libandroid_runtime.so (???)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   native: #10 pc 0166fdc3  /system/framework/arm/boot.oat (Java_android_util_Log_println_1native__IILjava_lang_String_2Ljava_lang_String_2+146)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.util.Log.println_native(Native method)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.util.Log.d(Log.java:164)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.Activity.performCreate(Activity.java:6291)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.ActivityThread.access$900(ActivityThread.java:177)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1450)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.os.Handler.dispatchMessage(Handler.java:102)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.os.Looper.loop(Looper.java:147)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.app.ActivityThread.main(ActivityThread.java:5953)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke!(Native method)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke(Method.java:372)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]   at android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
02-26 00:34:44.315 1109-1109/example.user.popmovie A/art: sart/runtime/check_jni.cc:65]
02-26 00:34:44.515 1109-1109/example.user.popmovie A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x40 in tid 1109 (e.user.popmovie)

0 个答案:

没有答案