Android Emulator崩溃 - 递增不起作用

时间:2012-07-10 17:51:19

标签: android

有人可以告诉我为什么它不起作用?当我编译但是android模拟器在第76行崩溃时,eclipse没有显示任何错误:“intrebare.setText(”Intrebarea“+ i + 1 +”:“+ intrebari [i]);”整个程序看起来像这样:

package com.example.testpsiho1;
import android.os.Bundle;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.AlertDialog;
import android.support.v4.app.NavUtils;
public class TestPsiho extends Activity {
 public static Button btna, btnb, btnc;
 public static TextView titlu, intrebare;
 public static String[] intrebari = {"intrebare 1", "intrebare 2", "intrebare 3"};
 public static String[] raspunsuriA = {"rasp a 1", "rasp a 2", "rasp a 3"};
 public static String[] raspunsuriB = {"rasp b 1", "rasp b 2", "rasp b 3"};
 public static String[] raspunsuriC = {"rasp c 1", "rasp c 2", "rasp c 3"};
 public static String[] rezultate = {"rezultatul pentru cele mai multe rasp a", "rezultatul pentru cele mai multe rasp b", "rezultatul pentru cele mai multe rasp c"};
 public static int a=0, b=0, c=0, i=1;
 public static String rezultat="";
 AlertDialog.Builder alert;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_psiho);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

}
public void click(View v){
        btna=(Button)findViewById(R.id.btna);
        btnb=(Button)findViewById(R.id.btnb);
        btnc=(Button)findViewById(R.id.btnc);
        intrebare=(TextView)findViewById(R.id.intrebare);
        if(i<4){
        if (v.equals(btna)) a++;
        if (v.equals(btna)) b++;
        if (v.equals(btna)) c++;

         intrebare.setText("Intrebarea " + i+1 + ": " + intrebari[i]);
         btna.setText(raspunsuriA[i]);
         btnb.setText(raspunsuriB[i]);
         btnc.setText(raspunsuriC[i]);

        }
        if(i==4){

            if (a >= b && a >= c){
                alert=new AlertDialog.Builder(this);

                  alert.setTitle("bla bla bla");
            }

    }
        i++;

}
}

2 个答案:

答案 0 :(得分:3)

你需要包装你的增量:

(i + 1)

如:

intrebare.setText("Intrebarea " + (i+1) + ": " + intrebari[i]);

答案 1 :(得分:0)

它不起作用,因为你的“i + 1”被假定为一个字符串。

我不知道它是否是最佳选择,但您可以用以下方法解决您的问题:

intrebare.setText(String.formatString("Intrebarea %s: ", i+1).concat(intrebari[i]));