Question Detail

Can't create handler inside thread that has not called Looper.prepare()

5 years ago Views 2898 Visit Post Reply

Why i am getting this error? i don't have any idea why it occur and how to resolve Can't create handler inside thread that has...

FATAL EXCEPTION: OkHttp Dispatcher
Process: com.google.fundook, PID: 3214
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:208)
at android.os.Handler.<init>(Handler.java:122)
at android.widget.Toast$TN.<init>(Toast.java:327)
at android.widget.Toast.<init>(Toast.java:92)
at android.widget.Toast.makeText(Toast.java:241)
 at com.google.fundook.PaymentPack.Payment_Activity$6$1.onReceived(Payment_Activity.java:443)
at com.google.fundook.StartUploadingClass$1.log(StartUploadingClass.java:60)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:263)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

02-28 10:44:49.996 3214-3214/com.google.fundook E/WindowManager: android.view.WindowLeaked: Activity com.google.fundook.PaymentPack.Payment_Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{425b4558 V.E..... R......D 0,0-640,434} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:422)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:250)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:286)
at com.google.fundook.validationPack.CustomeDialogClass.show(CustomeDialogClass.java:45)
at com.google.funbook.PaymentPack.Payment_Activity$6.onClick(Payment_Activity.java:425)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)


Thread Reply

Anonymous

- 5 years ago

I was also facing this issue I have added below item in my Main Style file make it false

<item name="android:windowDisablePreview">true</item>

to 

<item name="android:windowDisablePreview">false</item>

for more:- Here

 

Anonymous

- 5 years ago

Add this item to Your default AppTheme Style

<item name="android:windowDisablePreview">true</item>

Your Default base Style Will something like 

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  ...
    <item name="android:windowDisablePreview">true</item>
</style>

But I suggest you don't disable windowDisablePreview because it will disable your animations.

instead of above way you can change that white screen to your Application color theme by using this Style

<style name="StartUpTheme" parent="@android:style/Theme.Light.NoTitleBar.Fullscreen">
    <item name="android:windowBackground">@color/colorPrimary</item>
</style>

and use it in your Manifest file like 

<application 
        ...
 <activity
            android:name="com.google.androids.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/StartUpTheme">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>