Java 无法从其他类访问字符串?

Java 无法从其他类访问字符串?,java,android,sqlite,Java,Android,Sqlite,我正在关注android网站上的教程 在FeedReaderDbHelper中,SQL_数据_条目以红色点亮。如何从FeedReaderDbHelper访问它?我是选择接球手还是二传手,还是有更好的方法 //饲料阅读器 import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; /** * Crea

我正在关注android网站上的教程

在FeedReaderDbHelper中,SQL_数据_条目以红色点亮。如何从FeedReaderDbHelper访问它?我是选择接球手还是二传手,还是有更好的方法

//饲料阅读器

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Neil Armstrong on 6/5/2015.
 */
public class FeedReaderDbHelper extends SQLiteOpenHelper  {
    // If you change the database schema, you must increment the database version.
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "FeedReader.db";

    public FeedReaderDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // This database is only a cache for online data, so its upgrade policy is
        // to simply to discard the data and start over
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }
}
//馈线阅读器合同

import android.provider.BaseColumns;

/**
 * Created by Neil Armstrong on 6/5/2015.
 */
public final class FeedReaderContract {
    // To prevent someone from accidentally instantiating the contract class,
    // give it an empty constructor.
    public FeedReaderContract() {}

    /* Inner class that defines the table contents */
    public static abstract class FeedEntry implements BaseColumns {
        public static final String TABLE_NAME = "entry";
        public static final String COLUMN_NAME_ENTRY_ID = "entryid";
        public static final String COLUMN_NAME_TITLE = "title";
        public static final String COLUMN_NAME_SUBTITLE = "subtitle";
        private static final String TEXT_TYPE = " TEXT";
        private static final String COMMA_SEP = ",";
//this is what I am trying to get.
        private static final String SQL_CREATE_ENTRIES =
                "CREATE TABLE " + FeedEntry.TABLE_NAME + " (" +
                        FeedEntry._ID + " INTEGER PRIMARY KEY," +
                        FeedEntry.COLUMN_NAME_ENTRY_ID + TEXT_TYPE + COMMA_SEP +
                        FeedEntry.COLUMN_NAME_TITLE + TEXT_TYPE + COMMA_SEP +
         // Any other options for the CREATE command
                " )";

        private static final String SQL_DELETE_ENTRIES =
                "DROP TABLE IF EXISTS " + FeedEntry.TABLE_NAME;

    }
}

当您在
FreeReaderContract
类中使用
private String SQL\u CREATE\u ENTRIES
变量时,应该使用getter和setter来检索/编辑它

或者,您可以将它们打包为私有,并使用

FreeREaderContract.SQL\u创建\u条目


freerereaderdbhelper
类,因为它们是
静态
变量。(假设它们在同一个包中)

它们是静态变量,使用classname.variablename访问它,就像FeedReaderContract一样。TABLE_NAME如果它是私有属性,那么您必须使用getter,在您的问题或您提到的教程中,我看不到任何带有
SQL_DATA_条目的属性?私有静态最终字符串SQL_CREATE_ENTRIES=“CREATE TABLE”+FeedEntry.TABLE_NAME+(“+FeedEntry.\u ID+“整型主键,“+FeedEntry.COLUMN\u NAME\u ENTRY\u ID+TEXT\u TYPE+逗号\u SEP+FeedEntry.COLUMN\u NAME\u TITLE+TEXT\u TYPE+逗号\u SEP+//创建命令的任何其他选项”)”,它位于FeedReaderContract类中