小编Joh*_*ark的帖子

mapStateToProps不更新

我刚开始玩react/redux.我只想输入一些文本并点击提交,然后将其传递给另一个显示输入内容的组件.

我知道我可以从A点到B点获取数据,因为如果我使用store.subscribe而不是我可以访问状态并且它总是准确的.我试图使用mapStateToProps,但我没有运气.

我没有使用mapDispatchToProps所以这可能是一个问题?我似乎无法找到一个很好的简单例子.mapStateToProps似乎也只在我刷新页面时运行(使用webpack-dev-server),因为它只在页面加载时记录一次,而不再记录.

_______________ Input.js _________________

import React from 'react';
import store from '../redux/store';
import { connect } from 'react-redux';
import { addSearchParam } from '../redux/actions';

export default class Input extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      player: ''
    };

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {
    this.setState({
      player: event.target.value
    });
  }

  handleSubmit(event) {
    event.preventDefault();
    store.dispatch(addSearchParam(this.state.player))
  }

  render() {
    return ( <form onSubmit = {this.handleSubmit} >
      <label>
          <input type="text" value={this.state.player} 
          onChange={this.handleChange}/> 
      </label> 
      <input type="submit" value="Submit" /> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-redux

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

StringIndexOutOfBoundsException 字符串索引超出范围:0

我正在编写一个打开文本文件并检查注释的程序。然后它解析评论以检查某些单词。

我遇到的错误是以下 while 循环,该循环检查当前行是否以空格或“/”以外的任何字符开头(如果存在非反斜杠字符),然后 while 循环移动到下一行并检查再次。一旦 while 循环满足其要求并中断程序崩溃,我会收到以下输出错误。

import java.rmi.Naming;
import java.net.InetAddress;
i
import java.lang.reflect.*;
i
ERROR: String index out of range: 0 
at java.lang.String.charAt(Unknown Source) 
at ExtraCredit.main(ExtraCredit.java:22)</code></pre> 
Run Code Online (Sandbox Code Playgroud)

这是有问题的代码示例

System.out.println(line);
char x = line.charAt(0);
while((line.charAt(0)!='/')&&(Character.isWhitespace(x)==false))
{
    line = inputFile.nextLine();
    x = line.charAt(0);
    System.out.println(line);
    System.out.println(x);
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。我确信这是一个简单的错误,但我只是没有看到它。

java string exception

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

compareTo与heapSort的泛型

对于类,我必须实现BST或heapSort.我做了BST,但我觉得这也很好,但现在我被卡住了.这是我第一次与堆工作(和真正与仿制药的编码/实施可比,所以我对所有的错误道歉)和IM运行到实现的compareTo的问题.

基本上我希望能够将通用对象添加到我的堆数组中,然后将它们与Heap排序进行比较.我在使用compareTo来检查添加到堆中的新条目以及在reheap方法中进行交换.

我的错误返回:

Heap.java:64: error: bad operand types for binary operator '<'
if (this  < other)
          ^
first type:  Heap<T>
second type: Heap<T>

where T is a type-variable:
T extends Comparable<T> declared in class Heap
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题.我知道我的二元运算符不适用于泛型,但我不知道如何解决它.感谢您的任何意见.对于您可能找到的所有初学者错误感到抱歉!继承我的代码:

import java.util.*;

class Heap<T extends Comparable <T>>  implements Comparable<Heap<T>>{

private T[] heap;
private int lastIndex;
private static final int CAPACITY = 25;

public Heap(){

    this(CAPACITY);

}

public Heap(int capacity){

    heap = (T[])new Comparable[capacity+1];
    lastIndex = 0;
}

public void add(T newEntry){

    lastIndex++;
    if(lastIndex>=heap.length)
    doubleArray(); …
Run Code Online (Sandbox Code Playgroud)

java generics compareto heapsort

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

android webview占据整个屏幕

我是开发Android应用程序的新手,我正在制作一个基本的Web浏览器.到目前为止,我已经或多或少地按照我想要的方式工作了.我遇到的问题是一些网站加载全屏并覆盖我的按钮和editText的URL.例如reddit.com或notcot.org等网站显示在webview的给定区域,但facebook.com或yahoo.com等网站将重新加载并占据整个屏幕,覆盖我的按钮和editText栏,让我使用模拟器返回按钮而不是我制作的按钮.我真的不确定问题是什么,因为它似乎只发生在一些网站而不是其他网站.这是XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".ShowWeb" 
>

<LinearLayout
    android:id="@+id/linear1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
>
    <ImageButton
        android:id="@+id/backButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@null"
        android:onClick="onClick"
        android:src="@drawable/leftarrow" 
    />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginLeft="10dp"
        android:background="@color/white"
        android:hint="@string/hint"
        android:inputType="textUri" 
        android:isScrollContainer="true"
        android:maxWidth="225dp"
        android:scrollHorizontally="true"/>

   <ImageButton
        android:id="@+id/goButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
         android:layout_marginRight="5dp"
        android:background="@null"
        android:layout_gravity="center"
        android:onClick="onClick"
        android:src="@drawable/go" 
    />

    <ImageButton
        android:id="@+id/forwardButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@null"
        android:onClick="onClick"
        android:src="@drawable/rightarrow" 
     />   

  </LinearLayout>

   <WebView
       android:id="@+id/webBrowser"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_below="@+id/linear1" 
   />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

而Java代码是

import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View; …
Run Code Online (Sandbox Code Playgroud)

android webview

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

将listOf(mapOf(x,y,z))作为参数传递给Kotlin

对Kotlin来说很新,并且处理一个问题,需要我将这些值作为函数的参数

(
    starting = "begin",
    target = "end",
    edges =
    listOf(
        mapOf("start" to "x", "end" to "y", "distance" to 25)
    )
}
Run Code Online (Sandbox Code Playgroud)

我有前两个好,但地图列表让我很困惑.

a(starting: String, target: String, edges: ListOf(mapOf(x,y,z)){}
Run Code Online (Sandbox Code Playgroud)

谢谢

parameters kotlin

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