当我尝试为我的VpnService创建隧道接口时,我收到以下错误:
class Foo
{
//draw function and other stuff
};
ostream& operator<<(ostream& os, const vector< vector<char> >& grid)
{
}
我目前唯一的解决方法是在发生这种情况时重启设备。如果我不这样做,我根本无法创建隧道。
我创建隧道的代码:
Attempt to invoke virtual method 'java.lang.String android.os.ParcelFileDescriptor.toString()' on a null object reference
修改
根据文档,如果尚未准备好VpnService,// This is inside my VpnService implementation
private ParcelFileDescriptor configureTunnelWithPushOpts(PushOpts popts)
{
VpnService.Builder builder = this.new Builder();
builder.setMtu ( currentServerPrefs.SERVER_MTU );
builder.addAddress ( popts.ip, 32 );
builder.addDnsServer ( popts.dns1 );
builder.addDnsServer ( popts.dns2 );
builder.addRoute ( "0.0.0.0", 0 );
// Note: Blocking mode is now enabled in native
// code under the setFileDescriptor function.
// builder.setBlocking(true);
builder.setConfigureIntent(
PendingIntent.getActivity(
this,
0,
new Intent(
this,
MainActivity.class
),
PendingIntent.FLAG_UPDATE_CURRENT)
);
final ParcelFileDescriptor vpnInterface;
synchronized (this) {
builder.setSession(currentServerPrefs.SERVER_ADDRESS);
vpnInterface = builder.establish();
}
Logger.info("New interface: " + vpnInterface.toString(), this);
return vpnInterface;
}
函数将返回establish
,但是我在运行上述函数之前使用它来准备它。
null
我正在使用手机进行调试
// This is inside my MainActivity class
Intent intent = VpnService.prepare(getApplicationContext());
if (intent != null) {
startActivityForResult(intent, 0);
} else {
onActivityResult(0, RESULT_OK, null);
}
. . .
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Intent intent = new Intent(this, MyVpnService.class);
startService(intent);
}
}
修改
我想出了如何复制它以便它不再是零星的。 基本上,如果我在连接VPN时卸载应用程序,然后重新安装并尝试重新启动它,则在运行
Google Nexus 5 Running Android 5.0.1
时会收到空响应。我担心,当通过Google Play商店更新应用程序时,这可能会带来潜在问题。除此之外,请不要将此问题标记为重复。关于这个问题的每个其他问题都得到了答案,即在建造者建立之前需要准备服务,但是我在我的情况下准备它并且我的问题有不同的原因。任何帮助,将不胜感激。
答案 0 :(得分:1)
非常感谢提示,它带给我解决方案!
我在Android 5.0.2中遇到了同样的问题:一切正常,我安装了我正在开发的vpn应用程序。第二天突然发现NullPointerException
无法解析prepare
,但null
已正确调用。
可以通过以下步骤在我的环境中解决问题:
while (input}(
vector<Account> createAccObj;
if(input=="1"){
fillVector(createAccObj);
}else if(input=="2"){
printVector(createAccObj);
}
。