我试图在go中构建一个聊天室应用程序,并且我想在客户端使用ctrl + c或按终端的关闭按钮时调用注销功能。
我尝试了此处和此处给出的方法,但是它们没有捕获任何信号(在Windows 10和Fedora 23中尝试过)。这是我的代码段,
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
_ = <-sigc
fmt.Println("ctrl+c pressed")
client.Logout()
}()
Run Code Online (Sandbox Code Playgroud)
我还有其他使用goroutine并发运行的函数,这是该函数无法捕获任何信号的原因吗?
任何帮助,将不胜感激。
我正在开发一个带日期和显示日期的html页面.我正在使用一种名为Zeller同余的公式.但在JavaScript中,公式返回结果"NaN".我用Google搜索了问题.无法弄清楚解决方案.这是获取值的html.
<form method="post">
<br/>
day:<input id="dd" name="dd" type="text"/><br/>
month:<input id="mm" name="mm" type="text"/><br/>
year:<input id="yy" name="yy" type="text"/><br/>
<input type="submit" value="go" onclick="day()"/><br/>
</form>
Run Code Online (Sandbox Code Playgroud)
这是返回NaN的JavaScript公式.
function day() {
var d=document.getElementById("dd").value;
var m=document.getElementById("mm").value;
var y=document.getElementById("yy").value;
var h=(d+(((m+1)*26)/10)+y+(y/4)+6*(y/100)+(y/400))%7;//returns NaN
var d2=((h+5)%7); code continues..
Run Code Online (Sandbox Code Playgroud)
请帮我.
提前致谢.
我正在使用webview来创建应用程序.当我运行它显示的代码
不幸的是,app_name已停止
我在stackoverflow中提到了很多答案,但它们都没有为我工作.我甚至尝试在移动设备上安装相同的应用程序,它给出了同样的错误.
请参考以下代码.
MainActivity.java
package com.webception.demoappview;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}
Run Code Online (Sandbox Code Playgroud)
fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.webception.demoappview.MainActivity$PlaceholderFragment" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webception.demoappview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity …Run Code Online (Sandbox Code Playgroud)