Note that there are some explanatory texts on larger screens.

plurals
  1. POstart activity from custom dialog in android sdk 11 or higher
    text
    copied!<p>I have a problem and I am very confiused. I have a Dialog that it contains a Button. I show the dialog in main Activity with this code, so simple:</p> <pre><code>InfoDialog id=new InfoDialog(this); id.show(); </code></pre> <p>and I want when I click on Button, it starts the second activity. you see it is so easy, I use this code:</p> <pre><code>public class InfoDialog extends Dialog implements android.view.View.OnClickListener{ Context context; public InfoDialog(Context context) { super(context); setContentView(R.layout.infodialog); this.context=context; setupViews(); } private void setupViews() { Button button=(Button)findViewById(R.id.button1); button.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.button1: Intent newintent= new Intent(context,DestActivity.class); context.startActivity(newintent); break; } } </code></pre> <p>and I declare the destAct in Manifest too. when I run it on Gingerbread Android an older sdk versions it works fine. but when I run this code on ice cream sandwich (sdk 11) or higher it gives me force close!!! </p> <p>this is my log cat:</p> <pre><code>08-27 09:38:54.540: W/dalvikvm(10945): threadid=1: thread exiting with uncaught exception (group=0x40a3d1f8) 08-27 09:38:54.544: E/AndroidRuntime(10945): FATAL EXCEPTION: main 08-27 09:38:54.544: E/AndroidRuntime(10945): java.lang.NullPointerException 08-27 09:38:54.544: E/AndroidRuntime(10945): at my.app.InfoDialog.onClick(InfoDialog.java:131) 08-27 09:38:54.544: E/AndroidRuntime(10945): at android.view.View.performClick(View.java:3511) 08-27 09:38:54.544: E/AndroidRuntime(10945): at android.view.View$PerformClick.run(View.java:14105) 08-27 09:38:54.544: E/AndroidRuntime(10945): at android.os.Handler.handleCallback(Handler.java:605) 08-27 09:38:54.544: E/AndroidRuntime(10945): at android.os.Handler.dispatchMessage(Handler.java:92) 08-27 09:38:54.544: E/AndroidRuntime(10945): at android.os.Looper.loop(Looper.java:137) 08-27 09:38:54.544: E/AndroidRuntime(10945): at android.app.ActivityThread.main(ActivityThread.java:4575) 08-27 09:38:54.544: E/AndroidRuntime(10945): at java.lang.reflect.Method.invokeNative(Native Method) 08-27 09:38:54.544: E/AndroidRuntime(10945): at java.lang.reflect.Method.invoke(Method.java:511) 08-27 09:38:54.544: E/AndroidRuntime(10945): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 08-27 09:38:54.544: E/AndroidRuntime(10945): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 08-27 09:38:54.544: E/AndroidRuntime(10945): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>what the hell is this? please help me guys</p>
 

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