我想使用format()来打印一个字符串,但它的失败。错误是:空对象引用与控制台类
java.lang.NullPointerException:试图调用虚拟方法'java.io.Console java.io.Console.format(java.lang.String,java.lang.Object [])'on a空对象引用
下面是代码片段。希望提供任何提示
public class BootNotifier extends BroadcastReceiver
{
public String TAG = "BootNotifier";
Console console = System.console();
String fmt = "%s";
String msg = "Android boot completed successfully";
@Override
public void onReceive(Context context, Intent intent)
{
Log.e(TAG, "onReceive");
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))
{
Log.e(TAG, "onReceive: BOOT_COMPLETED");
console.format(fmt, msg);
}
}
}
这可能帮助:http://stackoverflow.com/questions/4203646/system-console-returns-null –
我敢肯定,Android不给你'Console'。 – chrylis