关于android中路径获取的有关问题

关于android中路径获取的问题
public static final String path ="/data/data/com.zhong.mobilesafe/files/address.db";
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null,SQLiteDatabase.OPEN_READONLY);
在path哪里提示Do not hardcode "/data/"; use Context.getFilesDir().getPath() instead
改成这样: public static final String path =Context.getFilesDir().getPath()+"/com.zhong.mobilesafe/files/address.db";
又提示:Cannot make a static reference to the non-static method getFilesDir() from the type Context
这个该怎么解决呢?求各位前辈指点一下。
------解决方案--------------------
getFilesDir是对象方法不是类方法,所以调用必须使用Context实例,如果在android组件中可以使用getApplicationContext()来获取context对象.
------解决方案--------------------
我建议你先学习一下java基础,如果不学好的话,可能学习android也会比较吃力.你可以看一下Thinking In Java中文版.
引用:
Quote: 引用:

getFilesDir是对象方法不是类方法,所以调用必须使用Context实例,如果在android组件中可以使用getApplicationContext()来获取context对象.

还是不太明白怎么用,下面贴上具体代码
public class AddressDao {
public static final String path = "/data/data/com.zhong.mobilesafe/files/address.db";
/**
 * 获取手机号码的归属地
 * 
 * @param number
 *            传入的手机号码
 * @return 归属地
 */
public static String getAddress(String number) {
String address = number;
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READONLY);
if (number.matches("^1[3458]\\d{9}$")) {
Cursor cursor = db
.rawQuery(
"select location  from data2 where id=(select outkey  from data1 where id=?)",
new String[] { number.substring(0, 7) });

if (cursor.moveToNext()) {
address = cursor.getString(0);
}
cursor.close();
}
db.close();
return address;

------解决方案--------------------
将类AddressDao 的构造函数修改为
pubic AddressDao (Context context)
{
           this.context = context;
}

然后在调用的时候获取
context.getFilesDir().getPath()获取路径。