簡體   English   中英

蝕中找不到源

[英]source not found in eclipse

我編寫了一個程序,該程序從用戶那里獲取數據並將其存儲在database.this數據庫存儲在資產文件夾中,並且當我編寫該程序並在行前使用斷點時它存在

 private OnClickListener mAddListener = new OnClickListener() {}

它給了我這個錯誤:找不到源。 我該怎么辦?

這是我的主要代碼:// ------------- mainactivity類---------------------

public class MainActivity extends Activity
{
    BDAdapter db = new BDAdapter(this);
    EditText name;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Capture our button from layout
        Button setButton = (Button)findViewById(R.id.go);
        Button getButton = (Button)findViewById(R.id.genRan);
        // Register the onClick listener with the implementation above
        setButton.setOnClickListener(mAddListener);
        getButton.setOnClickListener(mAddListener);



    }
    // Create an anonymous implementation of OnClickListener
    private OnClickListener mAddListener = new OnClickListener() 
    {
        public void onClick(View v) 
        {
            switch(v.getId())
            {
            case R.id.go:
                db.open();
                long id = 0;
                // do something when the button is clicked
                try
                {
                    name = (EditText)findViewById(R.id.Quote);
                    db.insertQuote(name.getText().toString());


                    id = db.getAllEntries();

                    Context context = getApplicationContext();
                    CharSequence text = "The quote '" + name.getText() + "' was added successfully!\nQuotes Total = " + id;
                    int duration = Toast.LENGTH_LONG;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                    name.setText("");
                }
                catch (Exception ex)
                {
                    Context context = getApplicationContext();
                    CharSequence text = ex.toString() + "ID = " + id;
                    int duration = Toast.LENGTH_LONG;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                }

                db.close();
                break;
            case R.id.genRan:
                db.open();
                //long id1 = 0;
                // do something when the button is clicked
                try
                {
                    //String quote = "";
                    //quote = db.getRandomEntry();
                    //Context context = getApplicationContext();
                    //CharSequence text = quote;
                    //int duration = Toast.LENGTH_LONG;

                    //Toast toast = Toast.makeText(context, text, duration);
                    //toast.show();

                     db.open();
                        Cursor c = db.getAllTitles();
                       if (c.moveToFirst())
                       {
                          do {          
                                DisplayTitle(c);
                            } while (c.moveToNext());
                       }
                        db.close();


                }
                catch (Exception ex)
                {
                    Context context = getApplicationContext();
                    CharSequence text = ex.toString();
                    int duration = Toast.LENGTH_LONG;

                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                }
                db.close();
            }
        }

    };
    public void DisplayTitle(Cursor c)
    {
        Toast.makeText(this, 
                "NAME: " + c.getString(0) + "\n" ,


                Toast.LENGTH_LONG).show();        
    } 


}

// ---------------------- DBAdapter類------------------------ ----

public class BDAdapter extends SQLiteOpenHelper {
     private Context mycontext;
int id=0;
     private String DB_PATH = "data/data/com.example.dd20/databases/";

        private static String DB_NAME = "ff.sqlite";
        public static final String KEY_ROWID = "_id";
        public static final String KEY_QUOTE = "name";
        public static final String DATABASE_TABLE = "ff1";
        private static final String TAG = "BDAdapter";
        public static final String DATABASE_CREATE =
                "create table ff1 (_id integer primary key, "
                        + "name text );";

     //   private DatabaseHelper DBHelper;
        private SQLiteDatabase db;
       // private SQLiteDatabase db;
        // the extension may be .sqlite
        // or .db
      //  public SQLiteDatabase myDataBase;

        public BDAdapter(Context context) {
            super(context, DB_NAME, null, 1);

            this.mycontext = context;

        }

        public void createDataBase() throws IOException{

            boolean dbExist = checkDataBase();

            if(dbExist){
            //do nothing - database already exist
            }else{

            //By calling this method and empty database will be created into the default system path
            //of your application so we are gonna be able to overwrite that database with our database.
            this.getReadableDatabase();

        //  try {

        //  copyDataBase();

        //  } catch (IOException e) {
     //      
        throw new Error("Error copying database");

      //    }
            }

            }

        private boolean checkDataBase(){

            SQLiteDatabase checkDB = null;

            try{
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

            }catch(SQLiteException e){

            //database does't exist yet.

            }

            if(checkDB != null){

            checkDB.close();

            }

            return checkDB != null ? true : false;
            }

      // private void copyDataBase() throws IOException{

            //Open your local db as the input stream
      //    InputStream myInput = mycontext.getAssets().open(DB_NAME);

            // Path to the just created empty db
      //    String outFileName = DB_PATH + DB_NAME;

            //Open the empty db as the output stream
      //    OutputStream myOutput = new FileOutputStream(outFileName);

            //transfer bytes from the inputfile to the outputfile
      //    byte[] buffer = new byte[1024];
      //    int length;
      //    while ((length = myInput.read(buffer))>0){
      //    myOutput.write(buffer, 0, length);
      //    }

            //Close the streams
        //  myOutput.flush();
      //    myOutput.close();
       //   myInput.close();

        //  }

        public void open() {
            // Open the database
             String myPath = DB_PATH + DB_NAME;
             db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

        }

        public synchronized void close() {
             if(db != null)
                 db.close();

                 super.close();
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL(DATABASE_CREATE);

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
           //  TODO Auto-generated method stub
      //  Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
         //       + newVersion + ", which will destroy all old data");
     //   db.execSQL("DROP TABLE IF EXISTS ff1");
  //   onCreate(db);


        }

        public long insertQuote(String Quote) 
        {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_QUOTE, Quote);
            return db.insert(DATABASE_TABLE, null, initialValues);
        }

        public int getAllEntries() 
        {
             Cursor cursor = db.rawQuery(
                        "SELECT COUNT(name) FROM ff1 ", null);
                    if(cursor.moveToFirst()) {
                        return cursor.getInt(0);
                    }
                    return cursor.getInt(0);

        }

        public String getRandomEntry() 
        {

            id = getAllEntries();
            Random random = new Random();
            int rand = random.nextInt(getAllEntries());
            if(rand == 0)
                ++rand;
            Cursor cursor = db.rawQuery(
                      "SELECT name FROM ff1", null);
                    //"SELECT * FROM tblRandomQuotes",null);
                    if(cursor.moveToFirst()) {
                        return cursor.getString(0);

                    }
                    return cursor.getString(0);

        }

        public Cursor getAllTitles() 
        {
            return db.query(DATABASE_TABLE, new String[] {

                    KEY_QUOTE,
                    }, 
                    null, 
                    null, 
                    null, 
                    null, 
                    null);
        }


}

如果你要調試onClickListener嘗試設置斷點switch(v.getId())開始與

查找Android操作系統的源必須atach源位置的系統類。 在日食中:

  • Ctl-單擊系統類
  • 在上下文菜單中選擇“打開聲明”項
  • 在我的情況下,選擇您的C:\\ Users \\\\ AppData \\ Local \\ Android \\ android-sdk \\ sources \\ android-

這將為您在所有系統類上提供JavaDoc幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM