Android应用程序未在模拟器上运行

时间:2015-03-29 21:41:44

标签: android emulation

我最近开始开发一个小型的Android琐碎游戏,当我在Android工作室的模拟器上运行它时,使用相关的SDK,它安装到模拟器上没有任何错误。但是当我尝试打开应用程序时模拟器,它说游戏不会运行 我只是想看看是否有其他人遇到过这个问题以及可以采取哪些措施来解决这个问题?

这是我的代码

主要活动

 public class MainActivity extends Activity {


List<Quiz> quizList;
int score = 0;
int qid = 0;
Quiz currentq;
TextView txtquestion;
RadioButton ra, rb, rc, rd;
Button bn;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    QBD qbd = new QBD(this);
    quizList = qbd.getAllQuestions();
    currentq = quizList.get(qid);
    txtquestion = (TextView) findViewById(R.id.Question);
    ra = (RadioButton) findViewById(R.id.R1);
    rb = (RadioButton) findViewById(R.id.R2);
    rc = (RadioButton) findViewById(R.id.R3);
    rd = (RadioButton) findViewById(R.id.R4);
    bn = (Button) findViewById(R.id.N);
    setQuestionView();
    bn.setOnClickListener(new View.OnClickListener()

    {
        @Override
        public void onClick (View v){
            RadioGroup rgr = (RadioGroup) findViewById(R.id.RG);
            RadioButton ans = (RadioButton) findViewById(rgr.getCheckedRadioButtonId());
            if (currentq.getRA().equals(ans.getText())) {
                score++;
            }
            currentq = quizList.get(qid);
            setQuestionView();
        }
    });


}

private void setQuestionView() {
    txtquestion.setText(currentq.getQ());
    ra.setText(currentq.getA());
    rb.setText(currentq.getB());
    rc.setText(currentq.getC());
    rd.setText(currentq.getD());
    qid++;
}







}

XML

 <?xml version="1.0" encoding="utf-8"?> 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent">


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical">



     <TextView
        android:id="@+id/Question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Text">


      </TextView>

      <RadioGroup
        android:id="@+id/RG"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <RadioButton
            android:id="@+id/R1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="button"/>
        <RadioButton
            android:id="@+id/R2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:text="button"/>

        <RadioButton
            android:id="@+id/R3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:text="button"/>
        <RadioButton
            android:id="@+id/R4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:text="button"/>


    </RadioGroup>
    <Button
        android:id="@+id/N"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/next"/>

 </LinearLayout>
 </RelativeLayout>

数据库帮助和类      package com.example.gregor.disseration2;

 import java.util.ArrayList;
 import java.util.List;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;

public class QBD extends  SQLiteOpenHelper{
private static  final int DATABASE = 1;
private static  final String DATABASE_NAME = "FUNWITHFLAGS";
private static  final String TABLE_FLAG ="flags";
private static  final String KEY_ID = "id";
private static  final String KEY_Q = "q";
private static  final String KEY_A = "a";
private static final  String KEY_B = "b";
private static final  String KEY_C = "c";
private static final  String KEY_D ="d";
private static final  String KEY_RA = "ra";
private SQLiteDatabase database;

public QBD(Context context){
    super(context,DATABASE_NAME, null, DATABASE);


}
@Override
public void onCreate(SQLiteDatabase db) {
    database= db;
    String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_FLAG + " ( "
            + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_Q
            + " TEXT, " + KEY_RA+ " TEXT, "+KEY_A +" TEXT, "
            +KEY_B +" TEXT, "+KEY_C+" TEXT"+KEY_D+"TEXT)";
    db.execSQL(sql);
    Quiz q1 = new Quiz("Which one of these flags has 52 Stars?", "USA", "UK", "Germany",
            "none of the above","A");
    this.addQuestionBank(q1);
    Quiz q2 = new Quiz("Which country has the St George Cross as it flags?", "USA", "England",
            "Jamaica ", "none of the above","B");
    this.addQuestionBank(q2);
    Quiz q3 = new Quiz("Which one of these countries does NOT have a tricolor?",
            "Italy", "UK", "Germany", "France","B");
    this.addQuestionBank(q3);
    Quiz q4 = new Quiz("Which one of these flags is NOT in the six nations?", "Tricolore",
            " il Tricolore", "Saltire", "Stars and Stripes","D");
    this.addQuestionBank(q4);
    Quiz q5 = new Quiz("What does a flag upside down s mean?", "Distress",
            " Safety", " A bit of drunken banter ", "None of the above","A");
    this.addQuestionBank(q5);

    db.close();
}




 @Override
    public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
  // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_FLAG);
   // Create tables again
       onCreate(db);
     }


   public void addQuestionBank(Quiz quest){
    //  SQLiteDatabase db =this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_Q,quest.getQ());
    values.put(KEY_RA,quest.getRA());
    values.put(KEY_A,quest.getA());
    values.put(KEY_B,quest.getB());
    values.put(KEY_C,quest.getC());
    values.put(KEY_D,quest.getD());
     database.insert(TABLE_FLAG,null,values);
  }
   public List<Quiz>getAllQuestions() {
      List<Quiz> quizl = new ArrayList<Quiz>();
     String selectQuery = "SELECT * FROM " + TABLE_FLAG;
      database = this.getReadableDatabase();
      Cursor cursor = database.rawQuery(selectQuery, null);
      if(cursor.moveToFirst()){
        do {
            Quiz qz = new Quiz();
            qz.setID(cursor.getInt(0));
            qz.setQ(cursor.getString(1));
            qz.setA(cursor.getString(2));
            qz.setB(cursor.getString(3));
            qz.setC(cursor.getString(4));
            qz.setD(cursor.getString(5));
            qz.setRA(cursor.getString(6));
            quizl.add(qz);
        } while (cursor.moveToNext());
    }
    return quizl;
   }
   public int  rowcount(){
    int row = 0;
    String selectQuery = "SELECT *FROM" + TABLE_FLAG;
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    row = cursor.getCount();
    return row;
}

}

public class Quiz{
   private int id;
   private String Q;
   private String A;
   private String B;
   private String C;
   private String D;
   private String RA;

public Quiz() {
    id = 0;
    Q = "";
    A = "";
    B = "";
    C = "";
    D = "";
    RA = "";

}


public Quiz(String q, String a, String b, String c, String d, String ra) {
    Q = q;
    A = a;
    B = b;
    C = c;
    D = d;
    RA = ra;

}


public int getID() {
    return id;

}
public String getQ()

{
    return Q;
}

public String getA()

{
    return A;
}



public String getB()

{
    return B;
}

public String getC()

{
    return C;
}

public String getD()

{
    return D;
}

public String getRA()

{
    return RA;
}

public void setID(int ID) {

    ID = id;
}

public void setQ(String q) {
    Q = q;
}

public void setA(String a) {
    A = a;

}

public void setB(String b) {
    B = b;

}

public void setC(String c) {
    C = c;

}

public void setD(String d) {
    D = d;

}

public void setRA(String ra) {
    RA = ra;

}

}

0 个答案:

没有答案