程序设计

专业和发烧友程序员的问答


26
Android Studio内联编译器显示红色错误,但使用gradle编译可正常工作
根据这个问题,我已经在Android Studio中设置了项目以使用Square Wire库。 Build-> Compile Project工作正常。 2:03:10 PM Compilation completed successfully in 31 sec 但是,如果我打开自己生成的协议缓冲区文件之一,则Square包将不会被识别。 另一个症状是,从Square Message类继承的方法在编辑器中显示为“无法解析方法”,即使它们可以正常构建并运行,但它们仍会编译错误。 除了build.gradle在项目中为模块添加依赖项之外,我还需要做更多的事情吗?


16
为什么在派生类中调用方法会调用基类方法?
考虑以下代码: class Program { static void Main(string[] args) { Person person = new Teacher(); person.ShowInfo(); Console.ReadLine(); } } public class Person { public void ShowInfo() { Console.WriteLine("I am Person"); } } public class Teacher : Person { public new void ShowInfo() { Console.WriteLine("I am Teacher"); } } 当我运行此代码时,将输出以下内容: 我是人 但是,您可以看到它是的实例Teacher,而不是的实例Person。代码为什么要这样做?
146 c#  class  derived-class 


30
Visual Studio 2013找不到单元测试
我在Visual Studio 2013中有一个简单的解决方案,它由一个Web项目,一个库项目和一个单元测试项目组成。当我打开解决方案并尝试运行单元测试时,Visual Studio不会发现它们。要运行测试,我尝试转到菜单并选择“测试”->“运行”->“运行所有测试”或打开“测试资源管理器”窗口。通过这些方法,Visual Studio不会在解决方案中发现任何测试。 首先创建一个简单的单元测试项目,然后尝试运行测试,Visual Studio知道发现该测试,然后我就可以运行它。然后,如果我打开以前的解决方案,Visual Studio现在会发现所有测试。我尝试保存我的解决方案,但先关闭并重新打开它,而无需先创建单元测试项目,Visual Studio不会再次找到测试。这是一个非常奇怪的行为,我不知道为什么会这样。 我曾经在这个项目中独自工作过,该项目使用的是与Visual Studio Team Foundation集成的源代码控制git。当一个新元素进入项目以及需要通过在线源代码控件重新创建解决方案时,Visual Studio的问题不会发现单元测试开始。在此之前,Visual Studio始终会发现所有测试。 为了创建单元测试,我使用了Microsoft.VisualStudio.QualityTools.UnitTestFramework dll。我的Visual Studio版本是:Microsoft Visual Studio Express 2013,用于Web版本12.0.30723.00更新3。我的.net Framework版本是4.5.50938。 我所有的测试都是这样的: [TestClass] public class Service1Test { [TestMethod] public void Test1() { Assert.IsTrue(True); } }

10
查找当前时间是否在某个时间范围内
使用.NET 3.5 我想确定当前时间是否在某个时间范围内。 到目前为止,我有currentime: DateTime currentTime = new DateTime(); currentTime.TimeOfDay; 我正在研究如何转换和比较时间范围。这行得通吗? if (Convert.ToDateTime("11:59") <= currentTime.TimeOfDay && Convert.ToDateTime("13:01") >= currentTime.TimeOfDay) { //match found } UPDATE1:谢谢大家的建议。我对TimeSpan函数不熟悉。
146 c#  datetime  timespan 

9
sys.argv [1]在脚本中的含义
我目前正在自学Python,只是想以简化的方式(参考下面的示例)想知道sys.argv[1]代表什么。它只是在要求输入吗? #!/usr/bin/python3.1 # import modules used here -- sys is a very standard one import sys # Gather our code in a main() function def main(): print ('Hello there', sys.argv[1]) # Command line args are in sys.argv[1], sys.argv[2] .. # sys.argv[0] is the script name itself and can be ignored …
146 python 


10
^ = 32背后的想法是什么,将小写字母转换为大写字母,反之亦然?
我正在解决代码部队上的一些问题。通常我首先检查字符是大写还是小写英文字母,然后减去或加上32以将其转换为相应的字母。但是我发现有人会^= 32做同样的事情。这里是: char foo = 'a'; foo ^= 32; char bar = 'A'; bar ^= 32; cout << foo << ' ' << bar << '\n'; // foo is A, and bar is a 我已经搜索了对此的解释,但没有找到。那为什么行得通呢?

30
IIS 7中的ASP MVC导致:HTTP错误403.14-禁止
我正在开发一个ASP MVC Web项目。现在,我有一个要求,迫使我将其部署到开发的IIS7中(以检查某些功能)。每当我尝试键入网站的URL时,我都会收到上述错误消息。(注意:开发机器:Vista Home Premium,IIS7) 到目前为止,我所做的是: 编辑了HOSTS文件(C:\ WINDOWS \ system32 \ drivers \ etc \ hosts)。 在其中放入两个域(127.0.0.1 domain1.com和127.0.0.1 domain2.com)。 创建了一个文件夹c:\ websites \ dirOfApplication,并将其从Visual Studio 8内部署到该文件夹​​。 在IIS7中,使用主机名domain1.com和应用程序文件夹创建了一个新站点。 在Web浏览器中键入地址domain1.com会导致上述错误(HTTP错误403.14-禁止-Web服务器配置为不列出此目录的内容。) 我想我丢失了一些东西,但不知道是什么!尝试以相同的结果部署文件System.Web.Mvc,System.Web.Abstraction和System.Web.Routing。每当我尝试按F5键并运行该应用程序时,它都可以正常运行!
146 asp.net-mvc  iis  hosting 

5
迅速落下
迅速有能力通过陈述吗?例如,如果我执行以下操作 var testVar = "hello" var result = 0 switch(testVal) { case "one": result = 1 case "two": result = 1 default: result = 3 } 案例“一”和案例“二”是否可以执行相同的代码?

9
有没有一种方法可以检查WPF当前是否在设计模式下执行?
有谁知道一些可用的全局状态变量,以便我可以检查代码当前是否正在设计模式下执行(例如在Blend或Visual Studio中)? 它看起来像这样: //pseudo code: if (Application.Current.ExecutingStatus == ExecutingStatus.DesignMode) { ... } 我需要这样做的原因是:当我的应用程序在Expression Blend中以设计模式显示时,我希望ViewModel改为使用其中包含模拟数据的“ Design Customer类”,设计人员可以在设计模式下查看。 但是,当应用程序实际执行时,我当然希望ViewModel使用返回真实数据的真实Customer类。 目前,我可以通过让设计者着手解决这个问题,在他进行设计之前,先进入ViewModel并将“ ApplicationDevelopmentMode.Executing”更改为“ ApplicationDevelopmentMode.Designing”: public CustomersViewModel() { _currentApplicationDevelopmentMode = ApplicationDevelopmentMode.Designing; } public ObservableCollection<Customer> GetAll { get { try { if (_currentApplicationDevelopmentMode == ApplicationDevelopmentMode.Developing) { return Customer.GetAll; } else { return CustomerDesign.GetAll; } } catch …
146 c#  wpf  expression-blend 


11
点破了。如何修复DistributionNotFound错误?
每当我尝试使用pip时,都会出现错误。例如: $ sudo pip install gevent-websocket Traceback (most recent call last): File "/usr/local/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module> parse_requirements(__requires__), Environment() File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: pip==0.8.1 我很想将pip的值更改为pip == 0.8.2 ..,但是我没有处理“ hacking”我的安装的后果...我正在运行python 2.7,pip的版本为0.8.2。
146 python  pip 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.