android - Trying an intent and crash the app -



android - Trying an intent and crash the app -

i'm trying create intent connect button class (definition of intent). problem that, when press button, crash. think problem in intent class. can see what's wrong? i'm trying open alert dialog when button bet pressed. have create it:

chips class, class ai want utilize after button pressed:

public class chips extends activity{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_game); } private alertdialog.builder dialog; public void scommessa () { dialog = new alertdialog.builder(this); final edittext txtinput = new edittext (this); final string stringinput = txtinput.gettext().tostring(); dialog.settitle("welcome poker"); dialog.setmessage("player 2, place bet!"); dialog.setview(txtinput); dialog.setpositivebutton("bet", new dialog.onclicklistener(){ @override public void onclick(dialoginterface dialog, int which) { int bet1 = 100; int intinput = integer.parseint(stringinput); int newplayer1bet = bet1 - intinput; string total1 = "" + newplayer1bet; } }); dialog.setnegativebutton("pass", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which){ toast.maketext(getapplicationcontext(), "player 2 won", toast.length_short).show();; } }); alertdialog dialogpoker = dialog.create(); dialogpoker.show(); } public void onclick(view v){ switch (v.getid()){ case r.id.cover1: scommessa(); break; } } }

then here class defined button , seek phone call class chips:

final button cover1 = (button) findviewbyid(r.id.cover1); final button button1 = (button) findviewbyid(r.id.a); final button button2 = (button) findviewbyid(r.id.b); final button button3 = (button) findviewbyid(r.id.c); final button button4 = (button) findviewbyid(r.id.d); final button button5 = (button) findviewbyid(r.id.e); final button bet = (button) findviewbyid(r.id.button1); cover1.setonclicklistener(new view.onclicklistener() { public void onclick(view v){ if(v.equals(cover1)){ button1.setbackgroundresource(r.drawable.back); button2.setbackgroundresource(r.drawable.back); button3.setbackgroundresource(r.drawable.back); button4.setbackgroundresource(r.drawable.back); button5.setbackgroundresource(r.drawable.back); } } }); button1.setonclicklistener(new view.onclicklistener() { public void onclick(view x){ if(x.equals(bet)){ intent intent1 = new intent(gameactivity.this, chips.class); startactivity(intent1); chips chip = new chips(); chip.scommessa(); } intent intent1 = new intent(gameactivity.this, chips.class); //startactivity(intent1); chips chip = new chips(); chip.scommessa(); } });

here manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.pokeroriginal" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="11" android:targetsdkversion="18" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.pokeroriginal.fullscreenactivity" android:configchanges="orientation|keyboardhidden|screensize" android:label="@string/app_name" android:screenorientation="portrait" android:theme="@android:style/theme.notitlebar" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <intent-filter> <action android:name="gameactivity" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name="com.example.pokeroriginal.gameactivity" android:label="@string/title_activity_game" android:screenorientation="landscape" android:theme="@android:style/theme.notitlebar"> </activity> <activity android:name= "com.example.pokeroriginal.chips" android:label= "@string/bet" android:screenorientation= "landscape" android:theme= "@android:style/theme.notitlebar"> </activity> </application> </manifest>

also activity_game.xml buttons defined:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/green_table_cloth" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".gameactivity" > <linearlayout android:id="@+id/linearlayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="20dp" android:orientation="horizontal" > <button android:id="@+id/cover1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cover" android:onclick="onclickchips" /> <button android:id="@+id/a" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="30dp" android:onclick="onclick" android:background="@drawable/back" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" > </view> <button android:id="@+id/b" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="onclick" android:background="@drawable/back" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" > </view> <button android:id="@+id/c" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="onclick" android:background="@drawable/back" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" > </view> <button android:id="@+id/d" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="onclick" android:background="@drawable/back" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" > </view> <button android:id="@+id/e" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginright="40dp" android:onclick="onclick" android:background="@drawable/back" /> <view android:layout_width="0dp" android:layout_height="0dp" > </view> </linearlayout> <imageswitcher android:id="@+id/imageswitcher1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <button android:id="@+id/button1" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="onclick(view x)" android:text="@string/bet" /> <button android:id="@+id/button01" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/bet" /> </imageswitcher> <linearlayout android:id="@+id/linearlayout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="60dp" android:orientation="horizontal" > <button android:id="@+id/cover2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cover" /> <button android:id="@+id/a2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="30dp" android:background="@drawable/back2" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" /> <button android:id="@+id/b2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/back2" /> <view android:layout_width="0dp" android:layout_height="10dp" android:layout_weight="1" /> <button android:id="@+id/c2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/back2" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" /> <button android:id="@+id/d2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/back2" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" /> <button android:id="@+id/e2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginright="10dp" android:background="@drawable/back2" /> <view android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" /> <!-- <imageview android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content"> </imageview> ' --> </linearlayout> <button android:id="@+id/button2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/bet" /> </linearlayout>

it's hard determine error without seeing logcat - should include in future.

looking @ code, notice in button1 onclicklistener:

intent intent1 = new intent(gameactivity.this, chips.class); startactivity(intent1); chips chip = new chips(); chip.scommessa();

to start activity, all need this:

intent intent1 = new intent(gameactivity.this, chips.class); startactivity(intent1);

i believe trying instantiate activity using it's constructor causing problems. when this, activity's views have not been setup properly, , when seek show dialog, encounter errors. seek removing these lines:

chips chip = new chips(); chip.scommessa();

your onclicklistener should this:

button1.setonclicklistener(new view.onclicklistener() { public void onclick(view x) { if (x.equals(bet)) { intent intent1 = new intent(gameactivity.this, chips.class); startactivity(intent1); } } });

android android-intent

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -