小编And*_*_CS的帖子

Java SimpleDateFormat的奇怪ArrayIndexOutOfBoundsException

我们运行Java 1.4.

我们有这个方法:

static SimpleDateFormat xmlFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

public static Date fromXml(String xmlDateTime) {
    ParsePosition pp = new ParsePosition(0);
    return xmlFormatter.parse(xmlDateTime, pp);
}
Run Code Online (Sandbox Code Playgroud)

其中xmlDateTime = 2013-08-22T16:03:00的例子.这一直有效,但突然停止了!

我们现在得到这个例外:

java.lang.ArrayIndexOutOfBoundsException: -1
at java.text.DigitList.fitsIntoLong(DigitList.java:170)
at java.text.DecimalFormat.parse(DecimalFormat.java:1064)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1381)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1159) 
Run Code Online (Sandbox Code Playgroud)

我试图通过使用不同的日期格式在单元测试中重现这一点,即:

2013-08-22T16:03:00
2013-08-22 16:03:00
Run Code Online (Sandbox Code Playgroud)

但没有运气!有任何想法吗?

java simpledateformat indexoutofboundsexception

16
推荐指数
2
解决办法
4769
查看次数

如何在.net中检测页面刷新

我有一个Button_click活动.在刷新页面时,先前的Postback事件再次触发.如何识别页面刷新事件以阻止该Postback操作?

我尝试了以下代码来解决它.实际上,我在SharePoint页面中添加了一个可视webpart.添加webpart是一个回发事件所以!每次我将webpart添加到页面时,回发总是假的,并且我在else循环中收到错误,因为对象引用是null.

if (!IsPostBack){
    ViewState["postids"] = System.Guid.NewGuid().ToString();
    Cache["postid"] = ViewState["postids"].ToString();
}
else{
    if (ViewState["postids"].ToString() != Cache["postid"].ToString()){
        IsPageRefresh = true;
    }
    Cache["postid"] = System.Guid.NewGuid().ToString();
    ViewState["postids"] = Cache["postid"].ToString();
}
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

c# asp.net sharepoint page-lifecycle sharepoint-object-model

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

在全屏模式下,滑动手势无法在YouTubePlayerView中运行

我正在使用YouTube API,我想在全屏模式下应用Swipe左右手势YouTubePlayerView.

在全屏模式下,Swipe手势在Android版本4.0+中不起作用YouTubePlayerView.

请帮我解决一下这个.提前致谢.

android youtube-api android-youtube-api

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

Django REST框架 - 来自外部提供商的OAuth2 Consumer API

我试图授权用户使用Oauth2从我的Django REST框架API访问一些资源.

关于Oauth2和API的大多数答案都涉及使API成为提供者.

但我计划与许多REST API共享一个Oauth2提供程序,我无法弄清楚如何使用它(而不是如何提供Oauth2).

我不知道用户如何登录提供者SSO,然后将其令牌传递给我的消费API,消费API必须针对我的提供者对用户进行身份验证(获取其信息,主要是授权).

有没有人知道如何从Django REST框架中使用Oauth2?

数字:

[用户] - > [我的API] < - > [Oauth2提供商(与django-oauth-provider)] < - > [Active Directory/anything]

python api django oauth-2.0 django-rest-framework

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

C++ std ::成员函数的线程

我正在尝试编写一个命令行服务器,它将从串行端口接收信息,解析它,并将其记录在内部对象中.

然后,根据客户端的请求,服务器将返回所请求的信息.

我想要做的是将接收器和解析器部件放在一个单独的线程中,以使服务器一起运行,而不是干扰数据收集.

#include <iostream>
#include <thread>

class exampleClass{
    std::thread *processThread;

    public void completeProcess(){
        while(1){
            processStep1();
            if (verification()){processStep2()}
        }
    };

    void processStep1(){...};
    void processStep2(){...};
    bool verification(){...};
    void runThreaded();
} // End example class definition

// The idea being that this thread runs independently
// until I call the object's destructor

exampleClass::runThreaded(){
    std::thread processThread(&exampleClass::completeProcess, this);
} // Unfortunately The program ends up crashing here with CIGARET
Run Code Online (Sandbox Code Playgroud)

c++ multithreading std

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

C/C++的rand()如何快速生成随机数?

我的理解是伪随机数生成器基本上只需要一些数字(种子),用一堆XOR和位移散列它,然后吐出一个非常长的数字,从中可以检索余数以获得"随机" "号码.

现在,通常你会time(NULL)在C/C++中用作rand()的种子.但是,time(NULL)每秒只增加一次,而不是每毫秒增加一次.那么,rand()如果种子仍然是相同的time(NULL)值,那么如何在不到一秒的时间内循环超过一千次并仍然可以得到不同的数字作为输出?

c++ random prng

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

奇怪的C++ Vector输出

我刚开始使用Vectors进行编码并编写了以下基本代码.

#include<iostream>
#include<vector>

using namespace std;

int main(){
    vector<int> second(4,100);

    cout<<second[0]<<endl; 
    cout<<second[1]<<endl; 
    cout<<second[2]<<endl; 
    cout<<second[3]<<endl; 
    cout<<second[4]<<endl; 
    cout<<second[5]<<endl; 
    cout<<second[6]<<endl; 
    cout<<second[7]<<endl; 

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到的输出如下

100
100
100
100
0
135145
0
0

RUN FINISHED; exit value 0; real time: 10ms; user: 0ms; system: 0ms
Run Code Online (Sandbox Code Playgroud)

为什么cout<<second[5]不同于其他指数的输出大于3.任何帮助表示赞赏.

c++ stdvector

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

如何在处理中向一个arraylist添加一个类?

每当我尝试添加一个country到我的ArrayList<country> 继续得到这个错误:unexpected token: (它突出我的countries.add线.我不确定为什么会这样.

class country  {
    private int mland, mwaters; //mtotalborders;
    private String mcenter;

    country(int earth, int aqua, String yn)  {
        mland = earth;
        mwaters = aqua;
        mcenter = yn;
    }
    public int getLand()  {
        return mland;
    }
    public int getWaters()  {
        return mwaters;
    }
    public int getTotalBorders()  {
        return mland+mwaters;
    }
    public String getCenter()  {
        return mcenter;
    }
}

country Turkey = new country(16, 7, "No");
country France = new country(22, …
Run Code Online (Sandbox Code Playgroud)

java processing arraylist

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

Java,反射,从类中获取方法

我在Java中使用反射时遇到了一些麻烦.我试图保存数据结构的方法,但收到错误.错误是

java.lang.NoSuchMethodException: cs671.eval.SerialList.add(java.lang.Integer, java.lang.String)

在这种情况下,我想要获取的方法是SerialList的add方法,该方法将Comparable和Object作为其参数.

structType = "cs671.eval.SerialList",, keyType = "java.lang.Integer"valType = "java.lang.String"是从文件中读入的字符串.

Class dataClass = null, comparableClass = null, objectClass = null;

try{ // create data structure
    dataClass = Class.forName(structType); 
    comparableClass = Class.forName(keyType);
    objectClass = Class.forName(valType);
}
catch(ClassNotFoundException e){}

java.lang.Object structObj = null;

try{ // Create a data structure object
    structObj = dataClass.newInstance();
}
catch(Exception e){}
Method m = null;
try{ // Attempt to get add method for the data structure
    m = dataClass.getMethod("add", comparableClass, …
Run Code Online (Sandbox Code Playgroud)

java reflection

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

C:二进制的无效操作数>(有'float'和'float(*)(float**,long int,long int,short int*)')

我写了一个非常简单的代码来查找数组中的max.我无法弄清楚这里有什么问题......

float maxValue(float **ArrayIn, long length, long width, short* result_coor){
    int i,j;
    float maxvalue = ArrayIn[0][0];
    for(i=0;i<length;i++){
        for(j=0;j<width;j++){
            if((ArrayIn[i][j]>maxValue)==1){
                maxValue = ArrayIn[i][j];
                result_coor[0] = i;
                result_coor[1] = j;
            }
        }
    }
    return maxvalue;
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

array_processing.c: In function ‘maxValue’:
array_processing.c:9:20: error: invalid operands to binary > (have ‘float’ and ‘float
(*)(float **, long int,  long int,  short int *)’)
array_processing.c:10:13: error: lvalue required as left operand of assignment
make: *** [array_processing.o] Error 1
Run Code Online (Sandbox Code Playgroud)

c

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

Java中的.equals()函数问题

我在Java中遇到了.equals函数的问题.我很确定问题是两个字符串不一样,即使它们看起来是物理眼睛(不同的格式).但我似乎无法调试它,所以想知道你们可能帮助我吗?

基本上这只是一小段代码,用于读取.CSV并解析前1-3个字减去任何数字.我知道它可以更好地编码,但它只能运行一次.它工作正常,但它假设删除目前无法正常工作的重复项.如果你们能够对我如何解决这个问题有所了解,那将非常感激.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class ReadCSVTest {
    public static void main(String[] args) { 
        ReadCSVTest obj = new ReadCSVTest();
        obj.run(); 
    }

    public void run() {
        String csvFile = "C:/Users/mrx/Documents/Standard Software.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";
        int count = 0;
        String duplicate = "";

        try {
            br = new BufferedReader(new FileReader(csvFile));
            while ((line = br.readLine()) != null) { 

                String[] product = line.split(cvsSplitBy);
                String app = product[0];
                app = …
Run Code Online (Sandbox Code Playgroud)

java string-comparison

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

C++开关不能使用2个以上的情况

我正在学习C++,很抱歉新手问题.
我正在从S. Prata的书中做练习.我现在在6.4.
我写的代码是:

#include <iostream>
using namespace std;
void showmenu();
void request();
const int strsize = 20;
const int templeSize = 5;

struct temple {
    char name[strsize];
    char job[strsize];
    char psd[strsize];
    int preference;
};

int main(){
    temple members[templeSize] = {
        {"Alan", "spy", "Kret", 0},
        {"Bruce", "engi", "Mech", 2},
        {"Zac", "engi", "Robot", 0},
        {"Kevin", "teacher", "Kid", 1},
        {"Maverick", "spy", "Shadow", 2}
    };

    char choice;
    showmenu();
    request();
    cin >> choice;
    while (choice != 'q'){
        switch(choice){
            case 'a' : for(int i; i< …
Run Code Online (Sandbox Code Playgroud)

c++ input switch-statement

0
推荐指数
2
解决办法
120
查看次数

接受一个单词,然后在java的新行上打印该单词的每个字母?

我需要用Java编写一个接受字符串/单词的程序,然后在新行上打印该单词的每个字母.例如,机器接受zip输出:

Z
I
P
Run Code Online (Sandbox Code Playgroud)

你是如何用java做的?任何简单的方法或方法都可以理解.

这是我到目前为止所拥有的:

import java.util.Scanner;
public class exercise_4{
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        int a;
        a = 0;

        System.out.println("Please enter your words");
        String word = scan.nextLine();
        System.out.println(word.charAt(a));
    }  
}
Run Code Online (Sandbox Code Playgroud)

java

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