i have develop game but after some time application was crashed and restart. when application crashed it show the message fatal signal 11 error.
Main Activity
Fatal signal 11 (SIGSEGV) at 0x00000058 (code=1), thread 8100 (l_jacksorbetter)
package com.vs.final_jacksorbetter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private Game g;
private Player p;
private int tempbet;
private String[] cards;
private Boolean secondTurn, hasStarted;
private Context context;
private TextView credtext,bettext,txtHold1,txtHold2,txtHold3,txtHold4,txtHold5,txtRank;
TextView tvJ,tvTP,tvTK,tvS,tvF,tvFH,tvFK,tvSF,tvRF;
boolean doubleBackToExitPressedOnce=false;
int i,x,y,creditstr2,result;
private Button betb,betMax,btnDouble;
LinearLayout ll1,ll2,ll3,ll4,ll5;
String creditStr,creditStr1;
static String val;
Animation animation;
MediaPlayer mp,mp1,mp2;
@Override
protected void onCreate(Bundle savedInstanceState) {
tempbet = 0;
secondTurn = false;
hasStarted = false;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
animation = new AlphaAnimation(1, 0);
animation.setDuration(700);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.REVERSE);
SharedPreferences sp = this.getSharedPreferences("MySharedPref", MODE_PRIVATE );
val = (sp.getString("Credit", "500"));
p = new Player();
tvJ = (TextView)findViewById(R.id.textView91);
tvTP = (TextView)findViewById(R.id.textView81);
tvTK = (TextView)findViewById(R.id.textView71);
tvS = (TextView)findViewById(R.id.textView61);
tvF = (TextView)findViewById(R.id.textView51);
tvFH = (TextView)findViewById(R.id.textView41);
tvFK = (TextView)findViewById(R.id.textView31);
tvSF = (TextView)findViewById(R.id.textView21);
tvRF = (TextView)findViewById(R.id.textView1);
txtHold1 = (TextView)findViewById(R.id.txt_Hold1);
txtHold2 = (TextView)findViewById(R.id.txt_Hold2);
txtHold3 = (TextView)findViewById(R.id.txt_Hold3);
txtHold4 = (TextView)findViewById(R.id.txt_Hold4);
txtHold5 = (TextView)findViewById(R.id.txt_Hold5);
txtRank = (TextView)findViewById(R.id.txtRank);
ll1 = (LinearLayout)findViewById(R.id.ll02);
ll2 = (LinearLayout)findViewById(R.id.ll03);
ll3 = (LinearLayout)findViewById(R.id.ll04);
ll4 = (LinearLayout)findViewById(R.id.ll05);
ll5 = (LinearLayout)findViewById(R.id.ll06);
context = getApplicationContext();
CharSequence text = "Place your bet, touch the deck to start";
Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
toast.show();
credtext = (TextView) findViewById(R.id.creditstextview);
credtext.setText("Credits: "+(CharSequence)(""+p.getCredits()));
//----------------------------------Button Achievement----------------------------
Button btnAchieve = (Button)findViewById(R.id.btn_Achievement);
btnAchieve.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this,AchievementsActivity.class);
startActivity(in);
}
});
//----------------------------------Button Deal------------------------------------
//mp = MediaPlayer.create(this, R.raw.beep);
// mp1 = MediaPlayer.create(this, R.raw.deal);
//mp2 = MediaPlayer.create(this, R.raw.hold);
final Button btn_Click = (Button)findViewById(R.id.btn_Deal);
btn_Click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(btn_Click.getText().toString().equals("DEAL")) {
btn_Click.setText("DRAW");
}
else if(btn_Click.getText().toString().equals("DRAW")) {
btn_Click.setText("DEAL");
}
if(!secondTurn)
startGame();
else
finalTurn();
secondTurn=!secondTurn;
}
});
for(int i=1;i<6;i++) {
final int tvar = i-1;
ImageView timv = (ImageView) findViewById(getResources().getIdentifier("card"+i, "id", getPackageName()));
timv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(secondTurn && hasStarted)
holdCard((ImageView)v, tvar);
}
});
}
//-----------------------------------Double Up-------------------------------------
btnDouble = (Button)findViewById(R.id.btn_DoubleUp);
btnDouble.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(btnDouble.getText().toString().equals("DOUBLE ON")) {
btnDouble.setText("DOUBLE OFF");
}
else if(btnDouble.getText().toString().equals("DOUBLE OFF")) {
btnDouble.setText("DOUBLE ON");
}
}
});
//-----------------------------------Bet Max---------------------------------------
betMax = (Button)findViewById(R.id.btn_BetMax);
betMax.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(tempbet+1<6 &tempbet<p.getCredits()) {
tempbet=5;
bettext.setText("Bet: "+(CharSequence)(""+tempbet));
if(tempbet==5) {
ll5.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll1.setBackgroundColor(Color.parseColor("#FFCC00"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
}
}
else {
v.setEnabled(false);
}
if(betMax.isClickable()) {
betb.setEnabled(false);
}
else {
betb.setEnabled(true);
}
}
});
//-------------------------------------------Bet Button------------------------------
bettext = (TextView) findViewById(R.id.txtBet);
betb = (Button) findViewById(R.id.btn_Bet);
betb.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//mp.start();
if(tempbet+1<6 &tempbet<p.getCredits()) {
tempbet++;
bettext.setText("Bet: "+(CharSequence)(""+tempbet));
if(tempbet==1) {
ll1.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
ll5.setBackgroundColor(Color.parseColor("#FFCC00"));
}
if(tempbet==2) {
ll2.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll1.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
ll5.setBackgroundColor(Color.parseColor("#FFCC00"));
}
if(tempbet==3) {
ll3.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll1.setBackgroundColor(Color.parseColor("#FFCC00"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
ll5.setBackgroundColor(Color.parseColor("#FFCC00"));
}
if(tempbet==4) {
ll4.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll1.setBackgroundColor(Color.parseColor("#FFCC00"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll5.setBackgroundColor(Color.parseColor("#FFCC00"));
}
if(tempbet==5) {
ll5.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll1.setBackgroundColor(Color.parseColor("#FFCC00"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
}
}
else
v.setEnabled(false);
}
});
}
//---------------------------------Start Game---------------------------------
private void startGame() {
tvJ.setTextColor(getResources().getColor(R.color.Black));
tvTP.setTextColor(getResources().getColor(R.color.Black));
tvTK.setTextColor(getResources().getColor(R.color.Black));
tvS.setTextColor(getResources().getColor(R.color.Black));
tvF.setTextColor(getResources().getColor(R.color.Black));
tvFH.setTextColor(getResources().getColor(R.color.Black));
tvFK.setTextColor(getResources().getColor(R.color.Black));
tvSF.setTextColor(getResources().getColor(R.color.Black));
tvRF.setTextColor(getResources().getColor(R.color.Black));
hasStarted=true;
if(tempbet==0)
tempbet=1;
g = new Game(p, tempbet);
betb.setEnabled(false);
betMax.setEnabled(false);
btnDouble.setEnabled(false);
p.setCredits(-g.bet);
credtext.setText("Credits: "+(CharSequence)(""+p.getCredits()));
y = p.getCredits();
creditStr1 = String.valueOf(y);
bettext.setText("Bet: "+(CharSequence)(""+g.bet));
if(tempbet==1) {
ll1.setBackgroundColor(Color.parseColor("#FE2E2E"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
ll5.setBackgroundColor(Color.parseColor("#FFCC00"));
}
cards = g.getCards();
for(int i=1;i<6;i++) {
ImageView card = (ImageView) findViewById(getResources().getIdentifier("card"+i, "id", getPackageName()));
card.setImageResource(g.t.cntable.get(cards[i-1]));
//mp1.start();
}
if(g.getRank().contentEquals("No Value"))
txtRank.setText("");
else
txtRank.setText(g.getRank());
}
//----------------------------------Final Round----------------------------------
private void finalTurn() {
g.dealCards();
cards = g.getCards();
g.showdown();
g.score();
if(btnDouble.getText().toString().equals("DOUBLE OFF"))
credtext.setText("Credits: "+(CharSequence)(""+p.getCredits()));
else
credtext.setText("Credits: "+(CharSequence)(""+creditStr1));
x = p.getCredits();
creditStr = String.valueOf(x);
//Toast.makeText(getApplicationContext(), "credit: "+creditStr.toString() , Toast.LENGTH_SHORT).show();
creditstr2 = x-y;
for(i=1;i<6;i++) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//TODO Auto-generated method stub
ImageView card = (ImageView) findViewById(getResources().getIdentifier("card"+i, "id", getPackageName()));
card.setImageResource(g.t.cntable.get(cards[i-1]));
//mp1.start();
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) card.getLayoutParams();
lp.setMargins(0, 0, 0, 0);
card.getDrawable().setColorFilter(null);
}
});
txtHold1.setVisibility(View.INVISIBLE);
txtHold2.setVisibility(View.INVISIBLE);
txtHold3.setVisibility(View.INVISIBLE);
txtHold4.setVisibility(View.INVISIBLE);
txtHold5.setVisibility(View.INVISIBLE);
ll1.setBackgroundColor(Color.parseColor("#FFCC00"));
ll2.setBackgroundColor(Color.parseColor("#FFCC00"));
ll3.setBackgroundColor(Color.parseColor("#FFCC00"));
ll4.setBackgroundColor(Color.parseColor("#FFCC00"));
ll5.setBackgroundColor(Color.parseColor("#FFCC00"));
}
SharedPreferences sp = MainActivity.this.getSharedPreferences("MySharedPref", MODE_PRIVATE);
SharedPreferences.Editor spEditor = sp.edit();
spEditor.putString("Credit", creditStr.toString());
spEditor.commit();
txtRank.startAnimation(animation);
if(g.getRank().contentEquals("No Value"))
txtRank.setText("Game Over");
else
txtRank.setText(g.getRank());
if(g.getRank().contentEquals("Jacks or Better"))
{
tvJ.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Two Pair"))
{
tvTP.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Three of a Kind"))
{
tvTK.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Straight"))
{
tvS.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Flush"))
{
tvF.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Full House"))
{
tvFH.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Four of a Kind"))
{
tvFK.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Straight Flush"))
{
tvSF.setTextColor(getResources().getColor(R.color.Red));
}
else if(g.getRank().contentEquals("Royal Flush"))
{
tvRF.setTextColor(getResources().getColor(R.color.Red));
}
if(btnDouble.getText().toString().equals("DOUBLE ON")) {
if((g.getRank().contentEquals("Jacks or Better"))||(g.getRank().contentEquals("Two Pair"))||(g.getRank().contentEquals("Three of a Kind"))
||(g.getRank().contentEquals("Straight"))||(g.getRank().contentEquals("Flush"))||(g.getRank().contentEquals("Full House"))
||(g.getRank().contentEquals("Four of a Kind"))||(g.getRank().contentEquals("Straight Flush"))||(g.getRank().contentEquals("Royal Flush")))
{
Intent intentBack = new Intent(MainActivity.this, DoubleUp_Confirm_Activity.class);
intentBack.putExtra("IntentType", "Credit");
intentBack.putExtra("Credits",creditStr1);
intentBack.putExtra("win", creditstr2);
intentBack.putExtra("array", cards);
startActivity(intentBack);
}}
g.bet=0;
tempbet=0;
bettext.setText("Bet: "+(CharSequence)(""+g.bet));
betb.setEnabled(true);
betMax.setEnabled(true);
btnDouble.setEnabled(true);
}
//------------------------------Hold Cards-----------------------------------------
private void holdCard(ImageView v, int i) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
Card thiscard = g.getSingleCard(i);
if(thiscard.isHeld()==false) {
switch (v.getId()) {
case R.id.card1:
//mp2.start();
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(0xEC0CF581, PorterDuff.Mode.MULTIPLY );
txtHold1.setVisibility(View.VISIBLE);
txtHold1.setText("Held");
break;
case R.id.card2:
//mp2.start();
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(0xEC0CF581, PorterDuff.Mode.MULTIPLY );
txtHold2.setVisibility(View.VISIBLE);
txtHold2.setText("Held");
break;
case R.id.card3:
//mp2.start();
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(0xEC0CF581, PorterDuff.Mode.MULTIPLY );
txtHold3.setVisibility(View.VISIBLE);
txtHold3.setText("Held");
break;
case R.id.card4:
//mp2.start();
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(0xEC0CF581, PorterDuff.Mode.MULTIPLY );
txtHold4.setVisibility(View.VISIBLE);
txtHold4.setText("Held");
break;
case R.id.card5:
//mp2.start();
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(0xEC0CF581, PorterDuff.Mode.MULTIPLY );
txtHold5.setVisibility(View.VISIBLE);
txtHold5.setText("Held");
break;
default:
break;
}
}
else {
switch (v.getId()) {
case R.id.card1:
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(null);
txtHold1.setVisibility(View.INVISIBLE);
break;
case R.id.card2:
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(null);
txtHold2.setVisibility(View.INVISIBLE);
break;
case R.id.card3:
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(null);
txtHold3.setVisibility(View.INVISIBLE);
break;
case R.id.card4:
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(null);
txtHold4.setVisibility(View.INVISIBLE);
break;
case R.id.card5:
lp.setMargins(0, 0, 0, 0);
v.getDrawable().setColorFilter(null);
txtHold5.setVisibility(View.INVISIBLE);
break;
default:
break;
}
}
thiscard.Held();
v.setLayoutParams(lp);
}
//----------------------------------------Double click to Exit---------------------------------------------
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if(secondTurn) {
Toast.makeText(this, "Please Complete this hand", Toast.LENGTH_SHORT).show();
}
else {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce=false;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
}, 2000);
}
}
}
User contributions licensed under CC BY-SA 3.0