0

有人可以告诉我为什么它不起作用吗?eclipse 在我编译时没有显示任何错误,但 android 模拟器在第 76 行崩溃:“ 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++;

}
}
4

2 回答 2

3

你需要包装你的增量:

(i + 1)

如:

intrebare.setText("Intrebarea " + (i+1) + ": " + intrebari[i]);
于 2012-07-10T17:53:42.213 回答
0

它不起作用,因为您的 "i+1" 被假定为字符串。

我不知道它是否是最好的选择,但您可以解决您的问题,将您的 setText 方法替换为:

intrebare.setText(String.formatString("Intrebarea %s: ", i+1).concat(intrebari[i]));
于 2012-07-10T18:11:47.123 回答