我试图将一个空的结构向量传递给一个函数,该函数将从一个文件中读取,它将返回读取的记录数 - 它将是一个整数.
我在main中初始化结构向量,当我尝试将它传递给函数时,我会定期执行它:
int read_records(vector<player> player_info)
Run Code Online (Sandbox Code Playgroud)
它给了我一个"玩家未定义"的错误.我已经找到了一种绕过它的方法,你将在下面的代码中看到,但是逻辑让我相信应该有一种方法来传递空向量而不必填写第一个下标.
代码如下.请注意,读取功能尚未完成,因为我仍然想知道结构的向量.
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;
//function prototypes
int read_records(struct player* player_info);
/*
* Define a struct called player that will consist
* of the variables that are needed to read in each
* record for the players. 2 strings for the first
* and last names and 1 integer to hold the statistics
*/
struct player
{
string first;
string last;
int stats; …Run Code Online (Sandbox Code Playgroud) 班级档案:
@Transactional(propagation=Propagation.REQUIRES_NEW)
public class ServiceImpl implements Service {
...
}
Run Code Online (Sandbox Code Playgroud)
Xml文件:
...
<bean id="service" class="com.sky.core.engine.impl.ServiceImpl">
...
Run Code Online (Sandbox Code Playgroud)
测试文件:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("testConfig.xml")
public class ServiceImplTest {
private static final Logger log = Logger
.getLogger(ServiceImplTest.class);
@Autowired
private ServiceImpl service;
@Test
public void test(){
...
}
Run Code Online (Sandbox Code Playgroud)
例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sky.core.engine.comp.impl.ServiceImplTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sky.core.engine.impl.ServiceImpl com.sky.core.engine.impl.Service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sky.core.engine.comp.impl.ServiceImpl] found for dependency: expected at …Run Code Online (Sandbox Code Playgroud) 从一个循环,我将得到的价值l.想象这个值是3.因此我想要一个字符串重复3次.这意味着我想要执行字符串*l,但这是不可能的,因为一个是字符串,一个是int.我确实需要字符串重复l次数.
例如,如果输入的字符串是"cat"并且l结果为3,我将得到输出"catcatcat".谢谢
这是我的编码:
import java.util.Scanner;
public class Task2 {
public static void main (String[] args){
Scanner kb=new Scanner(System.in);
System.out.println("Please give me a message:");
String strMessage = ("^[?=.*!@#$%^&*]+$");
strMessage=kb.nextLine();
System.out.println("Thank you! Now please give me a keyword:");
String strKeyword=kb.nextLine();
String strAlphabet= "abcdefghijklmnopqrstuvwxyz";
double Intlength2 = strKeyword.length();
double Intlength = strMessage.length();
double Intlength3 = Intlength/Intlength2;
Intlength3 = Intlength/Intlength2;
for (int l=0; l<Intlength3; l++){
Run Code Online (Sandbox Code Playgroud) JCheckbox虽然我以前经常使用它们,但我遇到了问题.
基本上,我创建一个带有复选框的非常简单的窗口,然后检查它们是否被选中.执行该检查时,JCheckbox即使不是,也会显示为已选中.这是我的代码.要重现我的问题,请运行该项目,然后单击"开始".即使createStatisticsFilesCheckBox设置为未选中,也要从构造函数中检查是否在ActionListener方法中选中它true.提前致谢!
包查询;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends Thread implements ActionListener
{
private JButton cancelButton, backButton, startButton;
private JCheckBox createQueriesCheckBox,createStatisticsFilesCheckBox, createPokerHandIDFilesCheckBox;
private JFrame frame;
public void actionPerformed(ActionEvent e)
{
if ("Start".equals(e.getActionCommand()))
{
if (createQueriesCheckBox.isSelected() == true);
{
// Code here
}
if (createStatisticsFilesCheckBox.isSelected() == true);
{
// Code here
// Always show as selected …Run Code Online (Sandbox Code Playgroud) 我试图计算第一个,甚至四百万个斐波那契数的总和.但是,过了一段时间,即使我使用标识符long,只有在值变大时才打印出Y值.
这些是起始值:
long amount = 4000000;
long x = 1;
long y = 2;
long sum = 2;
Run Code Online (Sandbox Code Playgroud)
这是一个for循环,总结并在程序运行时打印出数字.
for (int i = 0; i < amount - 1; i++) {
if (x > y) {
y = x + y;
if (y % 2 == 0) {
sum += y;
}
System.out.println("X: " + x);
} else {
x = x + y;
if (x % 2 == 0) {
sum += x;
}
System.out.println("Y: " + y);
} …Run Code Online (Sandbox Code Playgroud) 我有一个表更新导致死锁,并试图让Spring重试在方法获得某种锁定异常时重试.我已经尝试取出maxAttempts,值和退避但它似乎永远不会捕获任何异常.我错过了什么吗?我是否需要在Application文件中声明一个bean?任何帮助将非常感激!
@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {
Run Code Online (Sandbox Code Playgroud)
@Service
public class DetailService {
@Retryable(maxAttempts = 5, value = { LockAcquisitionException.class, ConcurrencyFailureException.class }, backoff = @Backoff(delay = 500, multiplier = 2) )
public void delete(final String detailCode) {
try {
this.delete(this.dao.findByDetailCode(detailCode));
} catch (LockAcquisitionException | ConcurrencyFailureException e) {
LOG.warn("Locking error! Going to retry", e.getMessage());
throw e;
}
}
public void delete(Details detail) {
this.dao.delete(detail);
}
@Retryable(maxAttempts = 5, value = { LockAcquisitionException.class, ConcurrencyFailureException.class }, backoff = @Backoff(delay = …Run Code Online (Sandbox Code Playgroud) 在我的 Spring Boot 应用程序中,我有以下@RestController方法:
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{decisionId}/decisions/{childDecisionId}/characteristics/{characteristicId}/values", method = RequestMethod.POST)
public ValueResponse create(@PathVariable @NotNull @DecimalMin("0") Long decisionId, @PathVariable @NotNull @DecimalMin("0") Long childDecisionId, @PathVariable @NotNull @DecimalMin("0") Long characteristicId,
@Valid @RequestBody CreateValueRequest request, Authentication authentication) {
....
request.getValue()
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的CreateValueRequest DTO:
public class CreateValueRequest implements Serializable {
private static final long serialVersionUID = -1741284079320130378L;
@NotNull
private Object value;
...
}
Run Code Online (Sandbox Code Playgroud)
例如,该值可以是String, Integer,Double以及相应的数组,例如String[], Integer[].. 等
如果是String, Integer, …
所以我有一个字符串:
**BOB**123(*&**blah**02938*(*&91820**FOO**
Run Code Online (Sandbox Code Playgroud)
我希望能够用来strtok消除每个单词.分隔符是每个不是字母的单个字符.
我被建议给我们isalpha,但不知道我会怎么做.有没有办法在不指定每个非字母字符的情况下执行此操作?
不幸的是,不允许使用正则表达式库.
我正在尝试编写一些代码来查找字符串中的子字符串。到目前为止,我有这个:
main = "dedicated"
sub = "cat"
count = 0
for i in range (0,len(main)):
match = True
if sub[0]==main[i]:
j=0
for j in range(0,len(sub)):
if sub[j]!=main[i+j]:
match = False
print "No substring"
break
else:
count=count+1
if match == True and count == len(sub):
print "Substring"
print "Position start:",i
Run Code Online (Sandbox Code Playgroud)
IndexError任何人都可以帮助我/给我指点/改进代码,使其与上面的要点一起正常工作吗?
我使用new动态声明数组.数组由字符串长度组成,我从用户那里得到.当我提供7-11之间的长度字符串时,数组正在打印垃圾值.为什么会这样?
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<ctime>
#include<map>
using namespace std;
int main(){
string str;
cin>>str;
int i,j;
int** arr = new int*[str.length()];
for(i = 0; i < str.length(); ++i)
arr[i] = new int[str.length()];
for(i=0;i<str.length();i++){
for(j=0;j<str.length();j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
字符串"BBABCBCAB"的输出是:
36397056 0 8 0 -1 0 1111573058 1094926915 0
0 0 4 0 -1 0 1111573058 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 …Run Code Online (Sandbox Code Playgroud) 我正在运行以下关于Java + Spark + SQL的示例.
但得到这个例外.编译时没有错误
我怎么能避免这个?无法找到有关此例外的任何内容.请帮我.
SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("JavaSparkSQL");
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
SQLContext sqlContext = new SQLContext(ctx);
Run Code Online (Sandbox Code Playgroud)
异常跟踪:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.spark.ui.SparkUI.addStaticHandler(Ljava/lang/String;Ljava/lang/String;)V
at org.apache.spark.sql.execution.ui.SQLTab.<init>(SQLTab.scala:36)
at org.apache.spark.sql.SQLContext$$anonfun$1.apply(SQLContext.scala:79)
at org.apache.spark.sql.SQLContext$$anonfun$1.apply(SQLContext.scala:79)
at scala.Option.foreach(Option.scala:257)
at org.apache.spark.sql.SQLContext.<init>(SQLContext.scala:79)
at org.apache.spark.sql.SQLContext.<init>(SQLContext.scala:69)
at org.sun.JavaSparkSQL.main(JavaSparkSQL.java:47)
2015-11-06 18:35:22,834 INFO org.apache.spark.SparkContext.logInfo:59 - Invoking stop() from shutdown hook
Run Code Online (Sandbox Code Playgroud)
pom.xml依赖项
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>1.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我以前尝试过,但在完整版本中几乎没有成功,但即使现在失败了,而且我显然在 Windows 上遗漏了一些东西(是的,它可能是 Windows :P)
有人可以带我过去吗
我正在使用 CMake gui For windows,尝试构建一个 VC2015 项目
我在构建 libgit2 时遇到的错误是
checking for module 'libssh2'
package 'libssh2' not found
LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.
Run Code Online (Sandbox Code Playgroud)
即使我已经把它放在每一个可能的地方,我认为它会看起来,我试过设置CMAKE_PREFIX_PATH?
如果有人在 Windows 上成功完成了它,我将不胜感激一两个关于我做错了什么或应该做什么的指针
谢谢罗伯特
我正在编写一个应用程序,生产者负责制作并发送消息,消费者负责接收消息。我必须在生产者应用程序中设置环境变量并在消费者应用程序中读取它。
在生产者应用程序中我执行了这个命令
putenv("MSG_KEY=15");
Run Code Online (Sandbox Code Playgroud)
在消费者应用程序中,我尝试获取这样的变量
char *z=getenv("MSG_KEY");
Run Code Online (Sandbox Code Playgroud)
但它不返回任何值(我得到零值)。如果我在生产者中编写相同的命令,如果我putenv()之前使用几行,它就会起作用。我认为问题在于它仅在本地设置变量,因此我无法从另一个程序访问它,但我不知道如何解决它。不知道这是否重要,但我使用的是Linux系统。
java ×7
c++ ×3
string ×3
c ×2
spring ×2
apache-spark ×1
arrays ×1
autowired ×1
file ×1
getenv ×1
hibernate ×1
integer ×1
jackson ×1
jcheckbox ×1
libgit2 ×1
libssh2 ×1
linux ×1
long-integer ×1
new-operator ×1
numbers ×1
openssl ×1
python ×1
spring-boot ×1
spring-retry ×1
substring ×1
swing ×1
vector ×1