2011-06-08 51 views
0

昨天我發佈了一個類似的問題,爲什麼我的代碼在我的內容提供者類而不是主類上開始,我收到了一些我已更新的反饋,但問題仍然存在仍然是代碼以ContentProvider類而不是主類開始的位置。我已經通過調試器運行代碼,它令人困惑,爲什麼代碼在Content Provider中開始並在Context階段傳回主類。我希望在這裏尋求幫助!從ContentProvider類開始而不是從Main類開始的Android代碼

主類是在這裏:

public class MedF1 extends Activity { 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.drug_list); 

    ListView drugListView; 
    ArrayAdapter<Drug> aa; 
    ArrayList<Drug> drugs = new ArrayList<Drug>(); 

    drugListView = (ListView)this.findViewById(R.id.list1); 
    DrugProvider.DatabaseHelper mDbHelper1 = new DrugProvider.DatabaseHelper(this); 

    //Creation of the Database here 
    try { 

    mDbHelper1.createDataBase(); 

    } catch (IOException ioe) { 

    throw new Error("Unable to create database"); 

    } 

    try { 

    mDbHelper1.openDataBase(); 

    }catch(SQLException sqle){ 

    throw sqle; 

    } 

內容提供商等級如下表所示。

public class DrugProvider extends ContentProvider { 

// publishing the URI for this provider 
public static final Uri CONTENT_URI = Uri 
     .parse("content://com.paad.provider.drug/drugs"); 

private static final int DRUGS = 1; 
private static final int DRUG_ID = 2; 
private static final UriMatcher uriMatcher; 

// allocating UriMatcher object 

static { 
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 
    uriMatcher.addURI("com.paad.provider.drug", "drugs", DRUGS); 
    uriMatcher.addURI("com.paad.provider.drug", "drugs/#", DRUG_ID); 
} 

// Column names 
public static final String KEY_ROWID = "_id"; 
public static final String KEY_DRUG = "drug"; 
public static final String KEY_CONTENT = "content"; 
public static final String KEY_INDICATION = "indication"; 
public static final String KEY_DOSAGE = "dosage"; 
public static final String KEY_SPECIALPRECAUTION = "specialprecaution"; 

// Column indexes 
public static final int DRUG_COLUMN = 1; 
public static final int CONTENT_COLUMN = 2; 
public static final int INDICATION_COLUMN = 3; 
public static final int DOSAGE_COLUMN = 4; 
public static final int SPECIALPRECAUTION_COLUMN = 5; 

// private DatabaseHelper mDbHelper; 
// private SQLiteDatabase mDb; 
private static String DB_PATH = "data/data/com.paad.MedF1/databases/"; 
private static String DB_NAME = "data"; 
private static final int DATABASE_VERSION = 1; 
private static final String DRUG_TABLE = "drugs"; 

public static SQLiteDatabase myDataBase; 



// Creation of the database and its basic parameters 
public static class DatabaseHelper extends SQLiteOpenHelper { 

    public final Context myContext; 

    public DatabaseHelper(Context context) { 

     super(context, DB_NAME, null, 1); 

     this.myContext = context; 

    } 

回答

1

嘿,我發現爲什麼代碼在ContentProvider而不是主類開始。這是因爲ContentProvider擴展附帶的實現方法(onCreate)。我改寫了另一個教程來創建它,但沒有真正理解它......這就是爲什麼。其他任何人面臨的問題應該嘗試探索內容提供者類中的onCreate方法是否影響它 - 它不是清單問題:)

0

感謝您的信息,調試器將無助於清單問題,您可以不要在清單中放入日誌條目或敬酒。