Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Pointer Exception when finding button on dialog
    text
    copied!<p>This is in my onCreate()</p> <pre><code>final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.go_pro); Button free = (Button) dialog.findViewById(R.id.still_free); free.setOnClickListener(new OnClickListener() { //EXCEPTION HERE! @Override public void onClick(View v) { dialog.cancel(); } }); </code></pre> <p>this is int the layout go_pro:</p> <pre><code> &lt;LinearLayout android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_width="wrap_content"&gt; &lt;Button android:id="@+id/still_free" android:text="Keep the ads" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt;&lt;/Button&gt; &lt;Button android:id="@+id/full_version" android:text="Go PRO" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;/LinearLayout&gt; </code></pre> <p>LogCat:</p> <pre><code>07-09 16:23:40.102: ERROR/AndroidRuntime(11435): FATAL EXCEPTION: main 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.convert/com.convert.MainWindowYuval}: java.lang.NullPointerException 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.os.Handler.dispatchMessage(Handler.java:99) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.os.Looper.loop(Looper.java:123) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at java.lang.reflect.Method.invokeNative(Native Method) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at java.lang.reflect.Method.invoke(Method.java:521) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at dalvik.system.NativeStart.main(Native Method) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): Caused by: java.lang.NullPointerException **07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at com.convert.MainWindowYuval.onCreate(MainWindowYuval.java:93)**MY CLASS!!@#!@#!@#!@#!@# 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 07-09 16:23:40.102: ERROR/AndroidRuntime(11435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) </code></pre> <p>EDIT: this is so wierd! i have two same buttons in my xml with different id and two buttons in the on create all the same but only one of them makes a null pointer exception</p> <pre><code> Button button1 = (Button) dialog.findViewById(R.id.full_version); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.paulmaidment.games.flagsoftheworld")); startActivity(intent); dialog.cancel();//TODO OPEN PAID APP HERE!!! } }); Button free = (Button)findViewById(R.id.stay_free); free.setOnClickListener(new OnClickListener() { //EXCEPTION ONLY HERE! @Override public void onClick(View v) { dialog.cancel(); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload