当我尝试为我的 VpnService 创建隧道接口(interface)时,出现以下错误:
Attempt to invoke virtual method 'java.lang.String android.os.ParcelFileDescriptor.toString()' on a null object reference
我目前唯一的解决办法是在发生这种情况时重启设备。否则,我根本无法创建隧道。
我创建隧道的代码:
// 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;
}
编辑:
根据文档,如果 VpnService 尚未准备好,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);
}
}
我用来调试的手机
运行 Android 5.0.1 的 Google Nexus 5
Edit
I figured out how to replicate it so that it's no longer sporadic. Basically, if I uninstall the application while the VPN is connected, and then reinstall it and try to start it back up, I receive a null response when i run
builder.establish(). I fear this could pose potential issues when the application is updated through the Google Play Store.Aside from that, Please do not mark this question as a duplicate. Every other question on this matter has been given the answer that the service needs to be prepared before the builder is established, however I am preparing it in my case and have a different cause for my problem. Any help would be appreciated.
最佳答案
非常感谢您的提示,它让我找到了解决方案!
我在 Android 5.0.2 中遇到了同样的问题:一切正常,我安装了我正在开发的 vpn 应用程序。第二天,尽管正确调用了 prepare,但突然出现无法解析的 NullPointerException。
可以通过以下步骤在我的环境中解决该问题:
null。关于Android VpnService.Builder.establish() 偶尔为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45257457/
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
s=Socket.new(Socket::AF_INET,Socket::SOCK_STREAM,0)s.connect(Socket.pack_sockaddr_in('port','hostname'))ssl=OpenSSL::SSL::SSLSocket.new(s,sslcert)ssl.connect从这里开始,如果ssl连接和底层套接字仍然是ESTABLISHED,或者它是否在默认值7200之后进入CLOSE_WAIT,我想检查一个线程几秒钟甚至更糟的是在实际上不需要.write()或.read()的情况下关闭。是用select()、IO.select()还是其他方法完成
我正在遍历数组中的一组标签名称,我想使用构建器打印每个标签名称,而不是求助于“我认为:builder=Nokogiri::XML::Builder.newdo|xml|fortagintagsxml.tag!tag,somevalendend会这样做,但它只是创建名称为“tag”的标签,并将标签变量作为元素的文本值。有人可以帮忙吗?这个看起来应该比较简单,我刚刚在搜索引擎上找不到答案。我可能没有以正确的方式提问。 最佳答案 尝试以下操作。如果我没记错的话,我添加了一个根节点,因为Nokogiri需要一个。builder=Nokogi
我正在尝试从googleAPI下载client_secret.json。我正在执行https://developers.google.com/gmail/api/quickstart/ruby中列出的步骤.使用此向导在GoogleDevelopersConsole中创建或选择项目并自动启用API。在左侧边栏中,选择同意屏幕。选择电子邮件地址并输入产品名称(如果尚未设置),然后单击“保存”按钮。在左侧边栏中,选择凭据并点击创建新客户端ID。选择应用程序类型已安装应用程序,已安装应用程序类型为其他,然后单击“创建客户端ID”按钮。点击新客户端ID下的下载JSON按钮。将此文件移动到您的工作
我正在使用pggem从Ruby与PostgreSQL对话。有没有检查是否没有结果比使用res.ntuples==0更好的方法?conn=PGconn.connectconfigcmd="select*fromlabelsinnerjoinlabels_mailusing(label_id)"+"wherelabels_mail.mail_id=$1andlabels.name=$2"res=conn.exec(cmd,[mail_id,mailbox])ifres.ntuples==0# 最佳答案 元组,打字错误?使用zero?比=
问题localhost:3000/users/不会显示我谦虚地进入,因为我是第一次尝试通过Rails教程。我在第10章,我已经花了5个小时解决这个问题。当我尝试访问localhost:3000/users/时出现错误(我相信这与factory_girl有关)解释了@users变量为空并且我忘记了为will_paginate传递一个集合对象。我目前在第10章第10.23节,每次运行时:$bundleexecrakedb:reset$bundleexecrakedb:populate$bundleexecrakedb:test:prepare我在解释时遇到错误rakeaborted!Fac
Web上有许多示例(例如http://techoctave.com/c7/posts/32-create-an-rss-feed-in-rails)展示了如何使用Builder制作漂亮的RSS提要。规范模板是这样的:xml.instruct!:xml,:version=>"1.0"xml.rss:version=>"2.0"doxml.channeldoxml.title"YourBlogTitle"xml.description"Ablogaboutsoftwareandchocolate"xml.linkposts_urlforpostin@postsxml.itemdoxml.t
我是Rails新手。得到下面的错误。我了解问题所在,但不确定如何解决?错误-参数缺失或值为空:客户defcustomer_paramsparams.require(:customer).permit(:first_name,:last_name,:email,:password,:password_confirmation)endendDetailsController.rbclassMy::Account::DetailsController:showelseredirect_tomy_account_details_path,:notice=>'Accountdetailsupda
如果params[:date]的参数为空,我希望我的text_field_tag将当前日期作为默认值,这是我目前的代码:我想要类似:谢谢 最佳答案 您可以简单地使用“或”运算符。如果params[:end]为空,它将使用Time.now。 关于ruby-on-rails-如果参数为空,则Text_field_tag默认值?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/35520
我的演示.rb:putsARGV.sizeARGV.eachdo|a|puts"Argument:#{a}"end结果取决于我们如何运行脚本:>demo.rbfoobar0>rubydemo.rbfoobar2Argument:fooArgument:bar为什么会这样?可以用这个做点什么吗?编辑:感谢所有回复!这是我的设置:>assoc.rb.rb=rbFile>ftyperbFilerbFile="c:\ruby-1.8.6\bin\ruby.exe""%1"%*所以看起来是对的。但是我发现了>demo.rbfoobar使用这样的命令行启动进程:"C:\ruby-1.8.7\bin