0

当它进入我的第二个活动时,首先它显示“不幸停止”,然后它做我想做的事情,活动向我展示了真相。那是什么样的错误?我该怎么办?

在我的第一个活动中:

  package com.example.mydic;

   import android.app.Activity;
 import android.graphics.Typeface;
import android.os.Bundle;
    import android.text.method.ScrollingMovementMethod;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.TextView;
   import android.widget.Toast;

   public class Review extends Activity{

       private dbHandler db;
    private TextView tv;
    private Button btn_yes;
    private Button btn_no;
    private int btn_click;
    private int btn_no_click;

    private TextView tv_mean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.review);

        db=new dbHandler(this);
        tv=(TextView) findViewById(R.id.re_tv_word);
        btn_yes=(Button) findViewById(R.id.re_btn_yes);
        btn_no=(Button) findViewById(R.id.re_btn_no);

    tv_mean=(TextView) findViewById(R.id.re_tv_mean);

    tv_mean.setMovementMethod(new ScrollingMovementMethod());

    Typeface textfont = Typeface.createFromAsset(getAssets(),"fonts/bnaznnbd.ttf");
    btn_yes.setTypeface(textfont);
    btn_no.setTypeface(textfont);



    db.open();
    tv.setText(db.First_record_Review());
    db.close();


    tv_mean.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {

            db.open();

            tv_mean.setText(db.First_record_Review_mean(tv.getText().toString()));

            db.close();


        }       

    });


    btn_yes.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            btn_click=btn_click+1;

            db.open();
            db.Review_id_check(tv.getText().toString(), Review.this, btn_click, btn_no_click);
            db.close();

            db.open();
            tv.setText(db.Move_To_Next(tv.getText().toString()));

            db.close();
            tv_mean.setText("نمایش معنا");



        }



    });


    btn_no.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            btn_no_click=btn_no_click+1;

            String word=tv.getText().toString();
            db.open(); 
            String mean=db.First_record_Review_mean(word);



            db.Review_id_check(tv.getText().toString(), Review.this, btn_click, btn_no_click);




            db.Review_Add_To_Fav(word, mean , getApplicationContext());





            tv.setText(db.Move_To_Next(tv.getText().toString()));
            db.close();
            tv_mean.setText("نمایش معنا");



        }

    });


}

@Override
protected void onResume() {
    super.onResume();




}



}

在我的第二个活动中:

   package com.example.mydic;

   import android.app.Activity;
   import android.content.Intent;
   import android.os.Bundle;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.TextView;
   import android.widget.Toast;

   public class Result extends Activity{

private dbHandler db;

private TextView tv_all;
public static TextView tv_true;
public static TextView tv_false;

private Button btn_main;
private Button btn_fav;

private String tc;
private String fc;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result);

    Bundle ex=getIntent().getExtras();
    tc=ex.getString("tc");
    fc=ex.getString("fc");  

    db=new dbHandler(this);
    tv_all=(TextView) findViewById(R.id.res_tv_all_count);
    tv_true=(TextView) findViewById(R.id.res_tv_true);
    tv_false=(TextView) findViewById(R.id.res_tv_false);

    btn_main=(Button) findViewById(R.id.res_btn_main);
    btn_fav=(Button) findViewById(R.id.res_btn_fav);



    db.open();
    tv_all.setText(String.valueOf(db.Review_all_count()));
    db.close();



    tv_false.setText(fc);


    tv_true.setText(tc);

btn_main.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View arg0) {
        tv_false.setText("");


        tv_true.setText("");
        tv_all.setText("");

        Intent i=new Intent(Result.this, Main.class);
        startActivity(i);

    }



});


}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
}

}

在我的 DBHandler 中:

    public String First_record_Review(){

    Cursor c = database.rawQuery( "SELECT * FROM test", null);
   c.moveToFirst();
   String name=c.getString(1);

    return name;


     }

    public String meaning(String word){

    Cursor c = database.rawQuery( "SELECT * FROM test where word Like  '"+word+"'", null);
   c.moveToFirst();
   String name=c.getString(2);

    return name;


    }


     public void add_to_fav_Review(String word, Context context){



    Cursor c = database.rawQuery( "SELECT * FROM test2 WHERE name Like '"+word+"'", null);

    if(c.moveToFirst()){
            Toast.makeText(context, "قبلا هم این لغت را بلد نبودید!", Toast.LENGTH_LONG).show();

    }else{

        ContentValues cv=new ContentValues();
        cv.put(dbhelper.scname, word);
        cv.put(dbhelper.scmean, meaning(word));

        database.insert(dbhelper.stblname, dbhelper.scname, cv);

            Toast.makeText(context, "لغت در لیست لغات ویژه ثبت شد", Toast.LENGTH_LONG).show();

    }


 }




       public String Review_id(String word){

    Cursor c = database.rawQuery( "SELECT * FROM test WHERE word Like '"+word+"'", null);
    c.moveToFirst(); 

    String r=c.getString(0);
    return r;


    }




       public String Move_To_Next(String word){
    Cursor c = database.rawQuery( "select * from test where id>"+Review_id(word), null);    
     c.moveToFirst();
    String t=c.getString(1);
    return t;    
    }



      public String Review_id_check(String word, Context activity, int                             yes_count, int  no_count){
    Cursor c = database.rawQuery( "select * from test where    id>"+Review_id(word), null);
    if(c.moveToFirst()){        
        return null;
    }else{
        Intent res=new  Intent(activity, Result.class);
        res.putExtra("tc", yes_count+"");
        res.putExtra("fc", no_count+"");
        activity.startActivity(res); 
        return null;
    }

       }



    public String First_record_Review_mean(String word){

    Cursor c = database.rawQuery( "SELECT * FROM test where word Like    '"+word+"'", null);
   c.moveToFirst();
   String name=c.getString(2);

    return name;


    }

       public Integer Review_all_count(){

    Cursor c = database.rawQuery( "SELECT * FROM test", null);

   int name=c.getCount();

    return name;


    }



   public void Review_Add_To_Fav(String word, String mean, Context context){



    Cursor c = database.rawQuery( "SELECT * FROM test2 WHERE name Like    '"+word+"'", null);

    if(c.moveToFirst()){

    }else{

        ContentValues cv=new ContentValues();
        cv.put(dbhelper.scname, word);
        cv.put(dbhelper.scmean, mean);

        database.insert(dbhelper.stblname, dbhelper.scname, cv);

        Toast.makeText(context, "نچ نچ نچ", Toast.LENGTH_LONG).show();

    }


 }

更新:

我将日志猫另存为txt,它是这样的:

09-10 19:46:14.757: E/AndroidRuntime(7146): 在 android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)

我的完整错误:

最新更新:

我认为方法 db.Move_to_Next 中的错误

因为:

09-10 20:23:00.601:E/AndroidRuntime(19444):在 com.example.mydic.dbHandler。Move_To_Next (dbHandler.java:652)

4

0 回答 0