I need a little help. I need change the color of a text view with java code.. I tried different way but it always gives me an error:
java.lang.NullPointerException
我尝试:
TextView sts;
sts = (TextView) findViewById(R.id.stato);
sts.setTextColor(Color.rgb(12,255,0));
或。
sts.setTextColor(android.graphics.Color.GREEN);
but both ways give me the same error on start.. My Class extends ListActivity
我怎么办? 预先感谢
FUL CODE:
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);