我需要一点帮助。我需要使用 java 代码更改文本视图的颜色。我尝试了不同的方法,但它总是给我一个错误:
java.lang.NullPointerException
我试过:
TextView sts;
sts = (TextView) findViewById(R.id.stato);
sts.setTextColor(Color.rgb(12,255,0));
或者..
sts.setTextColor(android.graphics.Color.GREEN);
但是这两种方式在开始时都会给我同样的错误。我的类扩展了 ListActivity
我如何?提前致谢
完整代码:
public class ProvaDatabase extends ListActivity{
TextView sts;
private DatabaseHelper databaseHelper;
@Override
public void onCreate(Bundle savedInstanceState)
{
sts = (TextView) findViewById(R.id.stato);
sts.setTextColor(android.graphics.Color.GREEN);
//sts.setTextColor(Color.rgb(12,255,0));
super.onCreate(savedInstanceState);
databaseHelper = new DatabaseHelper(this);
SQLiteDatabase db = databaseHelper.getWritableDatabase();
databaseHelper.insertdb(db, "sta", "25/11/2016", "SUCCESS", null, null, null);
databaseHelper.insertdb(db, "ssis", "25/11/2016", "WAITING", null, null, null);
databaseHelper.insertdb(db, "AAAAAAAA", "25/11/2016", "FAILED", null, null, null);
databaseHelper.insertdb(db, "BBBB", "bBBBBBB", "SUCCESS", null, null, null);
Cursor c = databaseHelper.getDB();
startManagingCursor(c);
setListAdapter(new SimpleCursorAdapter(this, R.layout.registryvista, c, new String[]
{ TabellaRegistry.TYPE, TabellaRegistry.DATE, TabellaRegistry.STATUS }, new int[]
{ R.id.tipo, R.id.data, R.id.stato }));
setContentView(R.layout.main2);