小编Al *_*ath的帖子

使用R.something的getSharedPreferences?

有这些线:

String app_name = "@string/app_name";
SharedPreferences sharedPreferences = getSharedPreferences(app_name, 0);
Run Code Online (Sandbox Code Playgroud)

我得到一个IllegalArgumentException:

File @ string/app_name.xml包含路径分隔符

如果我这样做:

SharedPreferences sharedPreferences = getSharedPreferences("MyAppName", 0);
Run Code Online (Sandbox Code Playgroud)

它运行正常,但如何在不对应用程序名称进行硬编码的情况下使用它?我不能使用R.string.app_name,因为那是一个int.

android sharedpreferences

1
推荐指数
1
解决办法
177
查看次数

Convert.ToDecimal(String.Format("{0:.##}",doubleAmount))不喜欢0.0

我对此行有格式化问题:

Decimal amount = Convert.ToDecimal(String.Format("{0:.##}", doubleAmount));  
Run Code Online (Sandbox Code Playgroud)

如果doubleAmount为0.0,则抛出格式异常.我该如何处理0.0?

.net c#

1
推荐指数
1
解决办法
996
查看次数

如何将UTC时间转换为本地时间

嗨,我正在将 UTC 时间从服务器传送到客户端的浏览器。时间显示正确,但时区没有。以下是时间的显示方式:

2014 年 7 月 15 日星期二 19:35:00 GMT-0500

日期和时间正确,但时区不正确。我只想将 GMT -0500 更改为 UTC。当我将其更改为 UTC 时,我可以将其转换为本地时间。

javascript timezone

1
推荐指数
1
解决办法
6878
查看次数

将pyodbc.Row转换为字符串

我需要将pyodbc.Row转换为字符串。互联网提供了一些建议,但这些建议似乎都不适合我。

row = cursor.fetchone() 
#unicodedata.normalize('NFKD', row).encode('ascii','ignore') #TypeError: must be unicode, not pyodbc.Row
#row.fieldname.encode('utf8') #AttributeError: 'pyodbc.Row' object has no attribute 'fieldname'
tblName = str(row)
tblName.replace("text:u","").replace("'","")
tblName = tblName.encode('utf-8')
print tblName
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了错误(以注释显示),或者似乎没有效果,如此处的输出所示:

(u'myTableName', ) # print tblName
Run Code Online (Sandbox Code Playgroud)

SQL是

tablesWithId = "select table_name \
                          from INFORMATION_SCHEMA.COLUMNS \
                          where COLUMN_NAME like 'MyId' "
cursor.execute(tablesWithId)
Run Code Online (Sandbox Code Playgroud)

Python 2.7

python pyodbc

1
推荐指数
1
解决办法
7642
查看次数

如何在流体中分配变量?

我想viewhelper可以帮助分配流量变量,我不希望变量从控制器传递.

typo3 fluid view-helpers

1
推荐指数
2
解决办法
1万
查看次数

在Windows 7上使用git为GitHub提供证书错误

目前,我收到此错误:

$ git clone https://github.com/square/haha.git
Cloning into 'haha'...
fatal: unable to access 'https://github.com/square/haha.git/': SSL certificate problem: self signed certificate in certificate chain
Run Code Online (Sandbox Code Playgroud)

我在Windows 7机器上.我了解到Github的证书是由DigiCert签署的.如果我查看" 受信任的根证书颁发机构">"证书",我会看到颁发给DigiCert的证书:

DigiCert Assured ID Root CA
DigiCert Assured ID Root G2
DigiCert Assured ID Root G3
DigiCert Global Root CA
DigiCert Global Root G2
DigiCert Global Root G3
DigiCert High Assurance EV Root CA
DigiCert Trusted Root G4
Run Code Online (Sandbox Code Playgroud)

GitHub证书是否包含在其中一个中?如果是这样,我该如何使用它?如果不是我如何得到它?

编辑 - 更多信息:
我可以将sslVerify设置为false并且它可以工作,但这当然不安全.
我可以使用git://而不是https://.这也有效,但不是https.

我不能使用SSH,因为此环境没有设置代理.使用ssh:

    $ git clone ssh://github.com/square/haha.git
    Cloning into 'haha'...
    D:/Program Files/Git/usr/bin/bash: -c: …
Run Code Online (Sandbox Code Playgroud)

git github digital-certificate

1
推荐指数
1
解决办法
8085
查看次数

C#/Xamarin 等效于 class.getSimpleName()

我正在手动将 Android Studio 项目移植到 Visual Studio/Xamarin。我有这个Java代码:

throw new IllegalStateException(MyClass.class.getSimpleName() + " is not initialized.");
Run Code Online (Sandbox Code Playgroud)

我正在尝试为.getSimpleName().

我在网上找到了一些可以尝试的东西:

throw new IllegalStateException(MyClass.ShortClassName +" is not initialized.);
throw new IllegalStateException(nameOf(MyClass) +  " is not initialized.");
Run Code Online (Sandbox Code Playgroud)

但这些都不编译。
你能告诉我什么是等价物吗?

c# xamarin.android

1
推荐指数
1
解决办法
438
查看次数

无法解析符号“setOnTouchListener”

Button button = (Button)findViewById(R.id.button1);

button.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN ) {
            //Insert desired code here
            return true;
        }
        return false;
    }
});

public void backtogreen(View view) {
    Intent intent = new Intent(this, DisplayMessageActivity.class);
    startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

如何修复此代码?我有这样的错误:

  • 无法解析符号“setOnTouchListener” - 用于 setOnTouchListener
  • 无效的方法声明;需要返回类型 - 用于 onTouchListener
  • 此处不允许注释 - 对于公共布尔值之上的@override
  • 无法为两个“事件”解析符号“事件”
  • 无法从具有 void 结果类型的方法返回值以返回 true 并返回 false

请帮忙!

android ontouchlistener android-activity

1
推荐指数
1
解决办法
2965
查看次数

New-SelfSignedCertificate -CertStoreLocation找不到路径

使用New-SelfSignedCertificate cmdlet,我要将硬盘上的位置指定为C:\ Development \ My Project。该命令:

New-SelfSignedCertificate -CertStoreLocation "cert:\LocalMachine\Development\My Project" 
Run Code Online (Sandbox Code Playgroud)

给出此错误:

找不到路径“证书:\ LocalMachine \ Development \ My Project”,因为它不存在。

我该怎么做呢?

$PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  962
Run Code Online (Sandbox Code Playgroud)

powershell certificate

1
推荐指数
1
解决办法
4007
查看次数

更改默认生成的 try-catch

在 Visual Studio 中,当我使用 ... try 进行环绕时,我得到了这个:

try
{
}
catch (Exception)
{
    throw;
}        
Run Code Online (Sandbox Code Playgroud)

我要这个:

try
{
}
catch (Exception exception)
{
    throw;
}        
Run Code Online (Sandbox Code Playgroud)

有没有办法更改默认值?

编辑:
Microsoft Visual Studio Enterprise 2015
版本 14.0.25425.01 更新 3

c# try-catch visual-studio

1
推荐指数
1
解决办法
1195
查看次数

如何不UserControl.dispose()

我有一种情况,用户点击UserControl的X,如果存在某种条件,我想继续显示用户控件.我认为召唤base.Dispose(false)可以解决问题,但事实并非如此.我该怎么做呢?

FeatureView.Designer.cs

partial class FeatureView
{
    // User clicked the X on the control
    protected override void Dispose(bool disposing)
    {
        // Note: base.GetType() = FeatureView
        if (someCondition) // then dispose
        {
            base.Dispose(true);
        }
        else // keep displaying the Feature, do not dispose
        {
            base.Dispose(false);  // nope
        }
    }
 }
Run Code Online (Sandbox Code Playgroud)

FeatureView.cs

 public partial class FeatureView : System.Windows.Forms.UserControl
 {

 }
Run Code Online (Sandbox Code Playgroud)

c# winforms

1
推荐指数
1
解决办法
89
查看次数

启用Panel上的所有控件

我想启用Panel上的所有控件.我可以像下面一样遍历Panel.这并不触及所有组件,只是顶级组件.我该怎么做呢?(这不是答案)

private void LoopThroughAllControls(System.Windows.Forms.Panel panel)
{
    for (int i = 0; i < panel.Controls.Count; i++)
    {
        panel.Controls[i].Enabled = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

ToolStrip添加ToolStripButton项目的代码:

this.toolStripContractor.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsbContractor_AddFile,
this.tsbContractor_View,
this.tsbContractor_Delete});
Run Code Online (Sandbox Code Playgroud)

c# winforms

-1
推荐指数
1
解决办法
234
查看次数

通过字典迭代元组

这更需要澄清:

如果我说:

for key, value in dictionary.iteritems():
Run Code Online (Sandbox Code Playgroud)

这实际上会给我键和值,而不是仅将每个键分配给"键"和"值"

这只是让我一直迷惑Python的东西吗?

python dictionary key-value

-3
推荐指数
1
解决办法
7351
查看次数