我正在编写一个应用程序,但是当我运行它时,它会出现黑屏。我已经调试和调试,无法找到出错的地方。谢谢你提前获得任何帮助。我正在尝试用希伯来语写一个刽子手游戏。 这是代码:
public class The_game extends AppCompatActivity {
boolean pressed = false;
int mistakes;
TextView score, categ, show;
Button a,b,g,d,h,v,z,ch,t,y,c,l,m,n,s,ah,p,tz,k,r,sh,th,contin;
boolean ai=true,bi=true,gi=true,di=true,hi=true,vi=true,zi=true,chi=true,ti=true,yi=true,ci=true,li=true,mi=true,ni=true,si=true,ahi=true,pi=true,tzi=true,ki=true,ri=true,shi=true,thi=true;
private ImageView hangman;
private points po=new points();
private String unknown="";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.the_game);
score = (TextView) findViewById(R.id.score);
a = (Button) findViewById(R.id.a);
b = (Button) findViewById(R.id.b);
g = (Button) findViewById(R.id.g);
d = (Button) findViewById(R.id.d);
h = (Button) findViewById(R.id.h);
v = (Button) findViewById(R.id.v);
z = (Button) findViewById(R.id.z);
ch = (Button) findViewById(R.id.ch);
t = (Button) findViewById(R.id.t);
y = (Button) findViewById(R.id.y);
c = (Button) findViewById(R.id.c);
l = (Button) findViewById(R.id.l);
m = (Button) findViewById(R.id.m);
n = (Button) findViewById(R.id.n);
s = (Button) findViewById(R.id.s);
ah = (Button) findViewById(R.id.ah);
p = (Button) findViewById(R.id.p);
tz = (Button) findViewById(R.id.tz);
k = (Button) findViewById(R.id.k);
r = (Button) findViewById(R.id.r);
sh = (Button) findViewById(R.id.sh);
th = (Button) findViewById(R.id.th);
contin = (Button) findViewById(R.id.contin);
categ = (TextView) findViewById(R.id.categ);
show = (TextView) findViewById(R.id.show);
hangman=(ImageView) findViewById(R.id.hangman);
contin.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent next=new Intent(The_game.this,EnterName.class);
next.putExtra("points", po.getPoints());
startActivity(next);
}
});
score.setText(Integer.toString(po.getPoints()));
newGame();
}
public void newGame() {
DBHelper db = new DBHelper(this);
int yellow = 15899407;
final int afor = 428720268;
a.setBackgroundColor(yellow);
b.setBackgroundColor(yellow);
g.setBackgroundColor(yellow);
d.setBackgroundColor(yellow);
h.setBackgroundColor(yellow);
a.setBackgroundColor(yellow);
v.setBackgroundColor(yellow);
z.setBackgroundColor(yellow);
ch.setBackgroundColor(yellow);
t.setBackgroundColor(yellow);
y.setBackgroundColor(yellow);
c.setBackgroundColor(yellow);
l.setBackgroundColor(yellow);
m.setBackgroundColor(yellow);
n.setBackgroundColor(yellow);
s.setBackgroundColor(yellow);
ah.setBackgroundColor(yellow);
p.setBackgroundColor(yellow);
tz.setBackgroundColor(yellow);
k.setBackgroundColor(yellow);
sh.setBackgroundColor(yellow);
th.setBackgroundColor(yellow);
hangman.setImageResource(R.drawable.mzer);
String[] word = db.getWord();
mistakes = 0;
categ.setText(word[1]);
unknown = "";
final String text = word[0];
final int number = text.length();
int spaces=0;
for (int i = 0; i < number; i++) {
if (text.charAt(i) != ' ') {
unknown=unknown+'_';
}
else {
unknown=unknown+'-';
spaces++;
}
}
show.setText(unknown);
while (7 > mistakes) {
int q = number-spaces;
for (int i = 0; i < number; i++) {
if ((text.charAt(i) != '_')&&(text.charAt(i) != '-')) {
q--;
}
}
if (q == 0) {
score.setText(Integer.toString(po.addPoints()));
newGame();
}
show.setText(unknown);
if (mistakes == 1) {
hangman.setImageResource(R.drawable.mone);
}
if (mistakes == 2) {
hangman.setImageResource(R.drawable.mtwo);
}
if (mistakes == 3) {
hangman.setImageResource(R.drawable.mthre);
}
if (mistakes == 4) {
hangman.setImageResource(R.drawable.mfor);
}
if (mistakes == 5) {
hangman.setImageResource(R.drawable.mfive);
}
if (mistakes == 6) {
hangman.setImageResource(R.drawable.msix);
}
while (!pressed) {
a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ai == true) {
pressed = true;
String unknown = getUnknown();
ai = false;
a.setBackgroundColor(10 * afor + 5);
boolean f = false;
for (int w = 0; w < number; w++) {
if (text.charAt(w) == 'א') {
f = true;
po.addPoint();
String part1 = unknown.substring(0, w);
String part2 = unknown.substring(w + 1);
unknown = part1 + 'א' + part2;
show.setText(unknown);
}
}
if (f != true) {
mistakes++;
}
}
}
});
(我删除了20个几乎完全相同的代码集,每个代码用于不同的希伯来字母。)
th.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (thi == true) {
pressed = true;
thi = false;
th.setBackgroundColor(10 * afor + 5);
String unknown = getUnknown();
boolean f = false;
for (int w = 0; w < number; w++) {
if (text.charAt(w) == 'ת') {
f = true;
po.addPoint();
String part1 = unknown.substring(0, w);
String part2 = unknown.substring(w + 1);
unknown = part1 + 'ת' + part2;
show.setText(unknown);
}
}
if (f != true) {
mistakes++;
}
}
}
});
}
pressed=false;
}
Intent lose = new Intent(The_game.this, EnterName.class);
lose.putExtra("points", po.getPoints());
startActivity(lose);
}
//else
{
//Toast.makeText(this, "אין לך מילים שהוכנסו. אנא הכנס מילים.", Toast.LENGTH_SHORT).show();
}
public String getUnknown() {
return unknown;
}
}
<?xml version="1.0" encoding="UTF-8"?>
-<RelativeLayout android:background="#ffffff" android:textDirection="rtl" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" android:theme="@android:style/Theme.NoTitleBar" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:layout_alignParentStart="true" android:layout_alignParentBottom="true" android:text="ת" android:layout_marginStart="16dp" android:layout_marginBottom="12dp" android:id="@+id/th"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ש" android:layout_marginStart="10dp" android:id="@+id/sh" android:layout_toEndOf="@+id/th" android:layout_alignBottom="@+id/th"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ר" android:layout_marginStart="10dp" android:id="@+id/r" android:layout_toEndOf="@+id/sh" android:layout_alignBottom="@+id/sh"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ק" android:layout_marginStart="10dp" android:id="@+id/k" android:layout_toEndOf="@+id/r" android:layout_alignBottom="@+id/r"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="צ" android:layout_marginStart="10dp" android:id="@+id/tz" android:layout_toEndOf="@+id/k" android:layout_alignBottom="@+id/k"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="פ" android:layout_marginStart="10dp" android:id="@+id/p" android:layout_toEndOf="@+id/tz" android:layout_alignBottom="@+id/tz"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ע" android:layout_marginStart="10dp" android:id="@+id/ah" android:layout_toEndOf="@+id/p" android:layout_alignBottom="@+id/p"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ס" android:layout_marginStart="10dp" android:id="@+id/s" android:layout_toEndOf="@+id/ah" android:layout_alignBottom="@+id/ah"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="נ" android:layout_marginBottom="11dp" android:id="@+id/n" android:layout_alignStart="@+id/th" android:layout_above="@+id/th"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="מ" android:id="@+id/m" android:layout_alignBottom="@+id/n" android:layout_alignStart="@+id/sh"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ל" android:id="@+id/l" android:layout_alignBottom="@+id/m" android:layout_alignStart="@+id/r"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="כ" android:id="@+id/c" android:layout_alignBottom="@+id/n" android:layout_alignStart="@+id/k"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="י" android:id="@+id/y" android:layout_alignBottom="@+id/c" android:layout_alignStart="@+id/tz"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ט" android:id="@+id/t" android:layout_alignBottom="@+id/y" android:layout_alignStart="@+id/p"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ח" android:id="@+id/ch" android:layout_alignBottom="@+id/m" android:layout_alignStart="@+id/ah"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ז" android:id="@+id/z" android:layout_alignBottom="@+id/ch" android:layout_alignStart="@+id/s"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ו" android:layout_marginBottom="12dp" android:id="@+id/v" android:layout_alignStart="@+id/m" android:layout_above="@+id/n"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ה" android:layout_marginBottom="12dp" android:id="@+id/h" android:layout_alignStart="@+id/l" android:layout_above="@+id/n"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ד" android:layout_marginBottom="12dp" android:id="@+id/d" android:layout_alignStart="@+id/c" android:layout_above="@+id/n"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ג" android:layout_marginBottom="12dp" android:id="@+id/g" android:layout_alignStart="@+id/y" android:layout_above="@+id/n"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="ב" android:layout_marginBottom="12dp" android:id="@+id/b" android:layout_alignStart="@+id/t" android:layout_above="@+id/n"/>
<Button android:background="#f29b0f" android:layout_height="40dp" android:layout_width="35dp" android:textSize="25dp" android:text="א" android:id="@+id/a" android:layout_alignLeft="@+id/ch" android:layout_below="@+id/hangman"/>
<TextView android:background="#ffffff" android:layout_height="48dp" android:layout_width="83dp" android:textSize="28dp" android:text="" android:id="@+id/score" android:layout_above="@+id/show" android:layout_alignParentTop="true" android:layout_toStartOf="@+id/categ" android:textColor="#020202"/>
<ImageView android:layout_height="35dp" android:layout_width="45dp" android:layout_alignParentStart="true" android:id="@+id/imageView" android:layout_above="@+id/show" android:layout_alignParentTop="true" android:layout_toStartOf="@+id/score" app:srcCompat="@drawable/cup"/>
<TextView android:textDirection="rtl" android:layout_height="70dp" android:layout_width="240dp" android:textSize="23dp" android:text="קטגוריה" android:id="@+id/categ" android:layout_alignParentTop="true" android:textColor="#000000" android:layout_alignParentEnd="true"/>
<TextView android:layout_height="230dp" android:layout_width="225dp" android:textSize="45dp" android:layout_alignParentStart="true" android:text="_________-_________" android:id="@+id/show" android:layout_below="@+id/categ" android:textColor="#000000"/>
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/hangman" android:layout_toEndOf="@+id/show" android:layout_above="@+id/b" android:layout_below="@+id/categ" app:srcCompat="@android:drawable/btn_star_big_on" android:layout_alignParentEnd="true"/>
<Button android:background="#c40010" android:layout_height="40dp" android:layout_width="35dp" android:textSize="12dp" android:text="ליציאה" android:id="@+id/contin" android:layout_alignLeft="@+id/z" android:layout_below="@+id/hangman"/>
</RelativeLayout>