小编And*_*sza的帖子

Java - 找到异常的第一个原因

我需要检查是否由某些数据库问题引起异常.我收到一个异常,并检查其原因是否包含"ORA"字符串并返回(类似"ORA-00001").这里的问题是我收到的异常嵌套在其他异常中,所以如果我不知道它是否是一个oracle异常,我必须检查该异常的原因,依此类推.有更清洁的方法吗?有没有办法知道给定异常的第一个原因(深层嵌套异常)?

我当前的代码如下所示:

private String getErrorOracle(Throwable e){
        final String ORACLE = "ORA";
        if (e.getCause() != null && e.getCause().toString().contains(ORACLE)){
            return e.getCause().toString();
        } else if(e.getCause() != null){
            return getErrorOracle(e.getCause());
        } else {
            return null;
        }
    }
Run Code Online (Sandbox Code Playgroud)

java oracle exception-handling ora-00001

34
推荐指数
3
解决办法
4万
查看次数

如何将XSD文件转换为C#类

我有一个XSD格式的文件.如何将其转换为C#类?

我需要在其他Web应用程序中使用类引用,我需要按照以下方式进行调用:

var res = client.Post<Customer>("/customers", c ); 
Run Code Online (Sandbox Code Playgroud)

c# xsd servicestack

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

如何读写多个文件?

我想为此编写一个程序:在一个文件夹中我有n个文件; 首先读取一个文件并执行一些操作,然后将结果存储在单独的文件中.然后读取第二个文件,再次执行操作并将结果保存到新的第二个文件中.对n个文件执行相同的过程.程序逐个读取所有文件,并分别存储每个文件的结果.请举例说明我是如何做到的.

python

13
推荐指数
3
解决办法
7万
查看次数

删除链表中的节点后,打印节点列表显示已删除的节点

在下面的代码中,即使在删除节点(20)之后,如果我尝试通过伪装将已删除的节点作为头部来打印所有节点,则它将打印所有节点以及已删除的节点.有人可以解释这种行为以及Java中的垃圾收集吗?即使删除的节点(20)没有下一个元素,它如何能够迭代所有节点?

节点:

class Node{

    int nodeint;
    Node next;

    public Node(int nodeint){
        this.nodeint = nodeint;

    }

}
Run Code Online (Sandbox Code Playgroud)

链表:

public class linkedlist{

    Node head;
    //Node next;
    public linkedlist(Node obj){

        this.head = obj;
    }

    public Node addnodes(int news){
        Node newlink = new Node(news);
        newlink.next = head;
        head = newlink;
        return head;
    }

    public void printAllNodes(Node obj){
        Node current  = obj;
        while(current!=null){
            System.out.println(current.nodeint);
            current = current.next;

        }

    }

    public Node remove(){

        Node temp = head;
        head = head.next;
        return temp;
    }

    public void printHead(){ …
Run Code Online (Sandbox Code Playgroud)

java linked-list singly-linked-list

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

如何在CollapsingToolbarLayout和Toolbar的中心放置文本?

我在工具栏的左侧和CollapsingToolbarLayout中有一个标题.我想将它水平移动到中心.请帮我.

我当前布局的图片和我想要实现的目标:

目前的布局1 目前的布局2

码:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sagar.materialdesigndemo.CollapsingToolbarFragment">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar_layout"
    android:layout_width="match_parent"
    android:layout_height="256dp"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="@dimen/toolbar_elevation"
        app:expandedTitleTextAppearance="@style/HeaderTitleStyle"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/flexible_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/backmain"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:titleTextAppearance="@style/ToolbarTitleStyle"
            android:layoutDirection="rtl"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

android persian android-layout android-toolbar android-collapsingtoolbarlayout

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

PowerShell:修改数组元素

我的cmdlet get-objects返回一个MyObject包含公共属性的数组:

public class MyObject{
    public string testString = "test";
}
Run Code Online (Sandbox Code Playgroud)

我希望没有编程技能的用户能够testString从数组的所有对象修改公共属性(如本示例中所示).然后将修改后的数组提供给我的第二个cmdlet,该cmdlet将对象保存到数据库中.

这意味着"编辑代码"的语法必须尽可能简单.

它应该看起来像这样:

> get-objects | foreach{$_.testString = "newValue"} | set-objects
Run Code Online (Sandbox Code Playgroud)

我知道这是不可能的,因为$ _只返回数组中元素的副本.

因此,您需要在循环中通过索引访问元素,然后修改属性.对于不熟悉编程的人来说,这真的很快变得非常复杂.


这样做有"用户友好"的内置方式吗?它不应该比简单更"复杂"foreach {property = value}

arrays powershell

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

我正在尝试制作基于控制台的战舰游戏,但我不知道如何设置船只

int randRow = rand.nextInt(rows-4);
int randColumn = rand.nextInt(columns); 
Run Code Online (Sandbox Code Playgroud)

在这里,我检查一下我的新船是否不会干扰我的第一艘船.整个数组都填充了包含'.'的对象.char除了第一艘船的位置

if(field[randRow][randColumn].value == '.' &&
    field[randRow][randColumn+1].value == '.' &&
    field[randRow][randColumn+2].value == '.' &&
    field[randRow][randColumn+3].value == '.'){
        field[randRow][randColumn] = new Square('b');
        field[randRow+1][randColumn] = new Square('b');
        field[randRow+2][randColumn] = new Square('b');
        field[randRow+3][randColumn] = new Square('b');

} else{
Run Code Online (Sandbox Code Playgroud)

如果我的新船不合适,我想用不同的随机值重试,但我不知道如何.

java console loops if-statement

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

我怎样才能调用另一个类的功能?

class Bishop : public ChessPiece {
    public:
    friend class Queen;
    Bishop(string colorIn, string nameIn);

    //isLegalMove for bishop
    //implemented this function for queen
    bool isLegalBishopMove(int xSrc, int ySrc, int xDest, int yDest);

    //Can move along any diagnol
    virtual bool isLegalMove(int xSrc, int ySrc, int xDest, int yDest) ;
};


class Queen : public ChessPiece {
 public:
    //friend class Bishop;

    Queen(string colorIn, string nameIn);
    //friend bool Bishop::isLegalBishopMove(int xSrc, int ySrc, int xDest, int yDest);

    virtual bool isLegalMove(int xSrc, int ySrc, int xDest, …
Run Code Online (Sandbox Code Playgroud)

c++ oop function friend

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

我的程序打印0而不是预期的数字

所以我创建了一个函数,它返回一个值,该值是用户给出的2个数字的连接(总和).但每次我输入这两个数字时,结果总会为0.

float connection(int num1, int num2, float result)
{
    result= num1 + num2;
    return (result);
}

int main()
{
  int num1= 0;
  int num2= 0;
  float result= 0.0;

  printf("\nChoose the first number you'd like to connect: ");
  scanf("%d", &num1);
  getchar();
  printf("choose the second number you'd like to connect: ");
  scanf("%d", &num2);
  connection(num1, num2, result);
  printf("The result is: %f", result);
}
Run Code Online (Sandbox Code Playgroud)

c

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