Open 4sskick opened 7 years ago
Hi @4sskick ,
Create Handler with Looper.getMainLooper() and in that handler call toast.
Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(),"Text you want to toast.",Toast.LENGTH_SHORT).show(); } });
I Am also facing the same issue after implementing above code.
Pls Help
` @Override public void hasInternetConnection() {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Conn_str_txt.setText("Connected");
}
});
}`
Error Message as below
Process: com.example.loop_the_request, PID: 2557 java.lang.RuntimeException: Unable to start service services.ConnectionService@efe403a with null: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4179) at android.app.ActivityThread.-wrap21(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2119) at android.os.Handler.dispatchMessage(Handler.java:108) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7529) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference at services.ConnectionService.onStartCommand(ConnectionService.java:50) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4151) at android.app.ActivityThread.-wrap21(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2119) at android.os.Handler.dispatchMessage(Handler.java:108) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7529) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Hi do you have any example working project that implement this snippet code? I've been tried to implement your snippet code with some improvements but I have this error when the first time run