11 Replies - 546 Views - Last Post: 04 July 2019 - 08:11 PM

#1 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 175
  • Joined: 24-February 15

OnClickListener causes app crash

Posted 30 June 2019 - 11:14 AM

What I'm doing wrong, after I put this onclickListener app won't start anymore.
// Creating variables for onclick
        ImageButton facebookIcon = new ImageButton(this).findViewById(id.facebook);
        ImageButton instagramIcon = new ImageButton(this).findViewById(id.instagram);
        // facebookIcon.setonclickListener(socialMediaClick);
        //instagramIcon.setonclickListener(socialMediaClick);

    }

    // Method for the right socialmedia redirection to the pages
    private View.onclickListener socialMediaClick = new View.onclickListener() {
        public void onclick(View v) {
            switch (v.getId() /*to get clicked view id**/) {
                case id.facebook:

                    // Go to the linked facebook page

                    break;

                case id.instagram:


                    break;
            }
        }
    };



Is This A Good Question/Topic? 0
  • +

Replies To: OnClickListener causes app crash

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12648
  • View blog
  • Posts: 45,822
  • Joined: 27-December 08

Re: OnClickListener causes app crash

Posted 30 June 2019 - 12:42 PM

What is the error message in the LogCat? Please post the entire stack trace, exactly as it appears.
Was This Post Helpful? 0
  • +
  • -

#3 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 55
  • View blog
  • Posts: 706
  • Joined: 23-September 15

Re: OnClickListener causes app crash

Posted 30 June 2019 - 08:12 PM

post stacktrace
Was This Post Helpful? 0
  • +
  • -

#4 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 175
  • Joined: 24-February 15

Re: OnClickListener causes app crash

Posted 01 July 2019 - 09:01 AM

This is a piece of it:

WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:42.166 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:42.168 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:43.167 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:43.170 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:43.893 1852-1871/? E/BatteryExternalStatsWorker: no controller energy info supplied for wifi
2019-06-30 19:47:44.168 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:44.170 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:45.170 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:45.171 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:45.492 3070-3101/? I/MicroDetectionWorker: #startMicroDetector [speakerMode: 0]
2019-06-30 19:47:45.493 3070-3101/? W/ErrorReporter: reportError [type: 211, code: 393244, bug: 0]: errorCode: 393244, engine: 0
2019-06-30 19:47:45.493 3070-3101/? I/MicroDetector: Keeping mic open: false
2019-06-30 19:47:45.493 3070-3101/? I/MicroDetectionWorker: #onerror(false)
2019-06-30 19:47:46.167 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:46.168 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:47.167 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:47.168 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:48.168 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:48.169 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:49.168 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:49.169 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:50.172 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:50.173 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:50.496 3070-3101/? I/MicroDetectionWorker: #startMicroDetector [speakerMode: 0]
2019-06-30 19:47:50.497 3070-3101/? W/ErrorReporter: reportError [type: 211, code: 393244, bug: 0]: errorCode: 393244, engine: 0
2019-06-30 19:47:50.497 3070-3101/? I/MicroDetector: Keeping mic open: false
2019-06-30 19:47:50.497 3070-3101/? I/MicroDetectionWorker: #onerror(false)
2019-06-30 19:47:51.171 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:51.172 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:52.171 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:52.171 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:53.171 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:53.172 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:54.176 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:54.178 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:55.175 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:55.178 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:55.503 3070-3101/? I/MicroDetectionWorker: #startMicroDetector [speakerMode: 0]
2019-06-30 19:47:55.506 3070-3101/? W/ErrorReporter: reportError [type: 211, code: 393244, bug: 0]: errorCode: 393244, engine: 0
2019-06-30 19:47:55.507 3070-3101/? I/MicroDetector: Keeping mic open: false
2019-06-30 19:47:55.507 3070-3101/? I/MicroDetectionWorker: #onerror(false)
2019-06-30 19:47:56.175 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:56.177 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:57.174 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:57.177 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:58.181 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:58.184 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:59.182 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:59.184 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:47:58.920 1852-1871/? E/BatteryExternalStatsWorker: no controller energy info supplied for wifi
2019-06-30 19:48:00.008 1852-1852/? I/ActivityManager: Killing 26384:com.google.android.dialer/u0a35 (adj 906): empty for 1827s
2019-06-30 19:48:00.011 1852-1869/? W/libprocessgroup: kill(-26384, 9) failed: No such process
2019-06-30 19:48:00.020 1721-1727/? D/hwcomposer: hw_composer sent 6 syncs in 60s
2019-06-30 19:48:00.049 1852-1869/? W/libprocessgroup: kill(-26384, 9) failed: No such process
2019-06-30 19:48:00.052 1695-1695/? I/Zygote: Process 26384 exited due to signal (9)
2019-06-30 19:48:00.090 1852-1869/? W/libprocessgroup: kill(-26384, 9) failed: No such process
2019-06-30 19:48:00.090 1852-1869/? I/libprocessgroup: Successfully killed process cgroup uid 10035 pid 26384 in 79ms
2019-06-30 19:48:00.180 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:00.182 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:00.515 3070-3101/? I/MicroDetectionWorker: #startMicroDetector [speakerMode: 0]
2019-06-30 19:48:00.517 3070-3101/? W/ErrorReporter: reportError [type: 211, code: 393244, bug: 0]: errorCode: 393244, engine: 0
2019-06-30 19:48:00.519 3070-3101/? I/MicroDetector: Keeping mic open: false
2019-06-30 19:48:00.519 3070-3101/? I/MicroDetectionWorker: #onerror(false)
2019-06-30 19:48:01.177 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:01.177 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:02.176 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:02.177 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:03.177 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:03.178 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:04.178 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:04.178 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:05.181 1852-1958/? I/GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:05.183 1852-1865/? I/GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$[email protected])
2019-06-30 19:48:05.522 3070-3101/? I/MicroDetectionWorker: #startMicroDetector [speakerMode: 0]
2019-06-30 19:48:05.523 3070-3101/? W/ErrorReporter: reportError [type: 211, code: 393244, bug: 0]: errorCode: 393244, engine: 0
2019-06-30 19:48:05.524 3070-3101/? I/MicroDetector: Keeping mic open: false
2019-06-30 19:48:05.525 3070-3101/? I/MicroDetectionWorker: #onerror(false)
Was This Post Helpful? 0
  • +
  • -

#5 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 55
  • View blog
  • Posts: 706
  • Joined: 23-September 15

Re: OnClickListener causes app crash

Posted 02 July 2019 - 01:17 AM

These doesn't looked like exception. An exception would normally start with

FATAL EXCEPTION:main...

This post has been edited by wseng92: 02 July 2019 - 01:20 AM

Was This Post Helpful? 0
  • +
  • -

#6 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 175
  • Joined: 24-February 15

Re: OnClickListener causes app crash

Posted 02 July 2019 - 03:07 AM

Is there is another reason why it is not working, because I think it is something with
  

// facebookIcon.setonclickListener(socialMediaClick);
//instagramIcon.setonclickListener(socialMediaClick);



Was This Post Helpful? 0
  • +
  • -

#7 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 55
  • View blog
  • Posts: 706
  • Joined: 23-September 15

Re: OnClickListener causes app crash

Posted 03 July 2019 - 02:33 AM

I don't see any errors from what you posted. Make sure you are posting the correct exception + relevant code.

This post has been edited by wseng92: 03 July 2019 - 02:34 AM

Was This Post Helpful? 0
  • +
  • -

#8 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 175
  • Joined: 24-February 15

Re: OnClickListener causes app crash

Posted 03 July 2019 - 03:51 AM

--------- beginning of crash
2019-07-03 12:35:53.480 28995-28995/com.izildo.android.navigationapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.izildo.android.navigationapp, PID: 28995
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.izildo.android.navigationapp/com.izildo.android.navigationapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setonclickListener(android.view.View$onclickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setonclickListener(android.view.View$onclickListener)' on a null object reference
at com.izildo.android.navigationapp.MainActivity.onCreate(MainActivity.java:46)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Was This Post Helpful? 0
  • +
  • -

#9 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 55
  • View blog
  • Posts: 706
  • Joined: 23-September 15

Re: OnClickListener causes app crash

Posted 03 July 2019 - 05:32 AM

The error is on imageButton.Make sure you use the correct id in xml.

This post has been edited by wseng92: 03 July 2019 - 05:34 AM

Was This Post Helpful? 0
  • +
  • -

#10 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 175
  • Joined: 24-February 15

Re: OnClickListener causes app crash

Posted 04 July 2019 - 09:48 AM

 <ImageButton
                android:id="@+id/instagram"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:src="@drawable/instagram"
                android:background="#ffffff"
                />

            <ImageButton
                android:id="@+id/facebook"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:src="@drawable/facebook"
                android:background="#ffffff"
                 />


Was This Post Helpful? 0
  • +
  • -

#11 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 175
  • Joined: 24-February 15

Re: OnClickListener causes app crash

Posted 04 July 2019 - 10:12 AM

NVM, I changed the way the code was written to read out the id for onclicklistener, now it works.
Was This Post Helpful? 0
  • +
  • -

#12 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 55
  • View blog
  • Posts: 706
  • Joined: 23-September 15

Re: OnClickListener causes app crash

Posted 04 July 2019 - 08:11 PM

(deleted)

This post has been edited by wseng92: 04 July 2019 - 08:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1