Android 切换活动给我一个空指针异常

Android 切换活动给我一个空指针异常,android,android-activity,nullpointerexception,Android,Android Activity,Nullpointerexception,切换活动的代码: Intent myIntent=new Intent(context,timeZones.class); context.startActivity(myIntent); 一旦这部分代码被命中,我会在这里得到一个空指针异常(特别是第2行): 我尝试添加布尔值以阻止画布绘制任何内容: Intent myIntent=new Intent(context,timeZones.class); context.startActivity(myIntent); dontDraw = t

切换活动的代码:

Intent myIntent=new Intent(context,timeZones.class);
context.startActivity(myIntent);
一旦这部分代码被命中,我会在这里得到一个空指针异常(特别是第2行):

我尝试添加布尔值以阻止画布绘制任何内容:

Intent myIntent=new Intent(context,timeZones.class);
context.startActivity(myIntent);
dontDraw = true;


protected void onDraw(Canvas canvas) {
    if (dontDraw == false)
    {
        canvas.drawColor(Color.WHITE);
    }
}
使用此布尔值,活动时区将运行,但它只是冻结


提前谢谢

好吧,我不完全明白,为什么你不试着理解你的bug的基础,而不是检查为什么
canvas
出现
null
你种植了愚蠢的解决方法…请添加更多的代码。代码是否到达第二个活动的
onCreate
Intent myIntent=new Intent(context,timeZones.class);
context.startActivity(myIntent);
dontDraw = true;


protected void onDraw(Canvas canvas) {
    if (dontDraw == false)
    {
        canvas.drawColor(Color.WHITE);
    }
}