尝试学习Audio API,但我得到BufferLoader类的Uncaught引用错误.我正在使用Chrome,它是最新的.本班不应该没有问题吗?
<html>
<head>
<script type=text/javascript>
window.onload = init;
var context;
var bufferLoader;
function init(){
context = new webkitAudioContext();
bufferLoader = new BufferLoader(
context,
[
' https://dl.dropboxusercontent.com/u/1957768/kdFFO3.wav',
' https://dl.dropboxusercontent.com/u/1957768/geniuse%20meodies.wav',
],
finishedLoading
);
bufferLoader.load();
}
function finishedLoading(bufferList){
//make two sources and play them
var source1 = context.createBufferSource();
var source2 = context.createBufferSource();
source1.buffer = bufferList[0];
source2.buffer = bufferList[1];
source1.connect(context.destination);
source2.connect(context.destination);
source1.start(0);
source2.start(0);
}
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有一个 FlatList,我试图每隔 X 秒滚动浏览数据数组的每个索引。现在我的数组中只有两项,但可能会有更多。当前的代码适用于前两次迭代,但随后它似乎没有正确重置,我得到了scrollToIndex out of range error: index is 2 but maximum is 1. 我认为当currentIndexis时>= data.length我的if语句会setCurrentIndex回到 0 但它似乎不起作用。基本上我想做的是自动循环 Flatlist 中的项目,但每个项目都会暂停几秒钟。
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import 'react-native-gesture-handler';
import React, {useState, useEffect, useRef} from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator, HeaderBackButton } from '@react-navigation/stack';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
ImageBackground,
Image,
TextInput,
Button, …Run Code Online (Sandbox Code Playgroud) 我一直在努力解决这个问题.首先,我有一个insertProduct(Product p)方法应该检查数据库中是否存在具有指定代码的产品.如果是这样,此方法将显示错误消息.否则,它应该将产品添加到数据库并将其打印到控制台.我不确定我是否正确这样做.
其次,该deleteProduct(Product p)方法应该删除该insertProduct方法添加的产品.现在的问题是,当我尝试添加产品时,我不断收到SQL异常,然后该deleteProduct方法只是在每次运行程序时都会逐个删除数据库中的产品,直到不存在为止.我不确定这两种方法都有什么问题.
控制台输出:
Derby has been started.
Product list:
bvbn Murach's Beginning Visual Basic .NET $49.50
cshp Murach's C# $49.50
java Murach's Beginning Java $49.50
jsps Murach's Java Servlets and JSP $49.50
mcb2 Murach's Mainframe COBOL $59.50
sqls Murach's SQL for SQL Server $49.50
zjcl Murach's OS/390 and z/OS JCL $62.50
First product:
bvbn Murach's Beginning Visual Basic .NET $49.50
Last product:
zjcl Murach's OS/390 and z/OS JCL $62.50
Product …Run Code Online (Sandbox Code Playgroud) 我正在关注正式的Webpack入门指南,我在使用配置部分时收到错误.它说创建一个webpack.config.js文件:
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
}
};
Run Code Online (Sandbox Code Playgroud)
然后我运行以下命令:
npx webpack --config webpack.config.js
我得到的错误是:
Cannot find module '/Users/Documents/Web_Development/tone/webpack.config.js'
该指南似乎没有提出任何可能出错的想法.我的代码编辑器也告诉我const path = require('path');说"预期JSON对象,数组或文字;
我的目录结构:
webpack.config.json
package.json.lock
package.json
node_modules/
dist/
index.html
main.js
src/
index.js
Run Code Online (Sandbox Code Playgroud)
的package.json:
{
"name": "tone",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"webpack": …Run Code Online (Sandbox Code Playgroud) 试图将变量'randomWord'打印到console.log,但chrome表示它没有定义.它看起来像是我定义的.为什么不打印到console.log?
function strt(){
//get random word from words[] array
var randomWord = words[Math.floor(Math.random()* words.length)];
var wordLength = randomWord.length;
//create a blank boxes or div elements for holding each letter of
// selected random word
for(i = 0 ; i< wordLength; i++){
var divTag = document.createElement("div");
divTag.id = "div" + i;
divTag.className = 'wordy';
//divTag.innerHTML = randomWord[i];
hangManDiv.appendChild(divTag);
};// end for loop
//disable start button
document.getElementsByName("startB")[0].disabled = true;
return randomWord;
}//end strt()
console.log(randomWord);
Run Code Online (Sandbox Code Playgroud) 我正在尝试从java书籍中进行练习.代码按原样出现,除了设置数据库的路径之外,我还没有在代码中添加任何内容.我在OSX上,所以我不得不安装Apache Derby.每次我构建并运行程序时,我都会得到:
Derby has been started.
Product list:
bvbn Murach's Beginning Visual Basic .NET $49.50
cshp Murach's C# $49.50
java Murach's Beginning Java $49.50
jsps Murach's Java Servlets and JSP $49.50
mcb2 Murach's Mainframe COBOL $59.50
sqls Murach's SQL for SQL Server $49.50
zjcl Murach's OS/390 and z/OS JCL $62.50
Exception in thread "main" java.lang.NullPointerException
First product:
at DBTesterApp.printProduct(DBTesterApp.java:117)
at DBTesterApp.printFirstProduct(DBTesterApp.java:66)
at DBTesterApp.main(DBTesterApp.java:16)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
Run Code Online (Sandbox Code Playgroud)
我很困惑为什么这个异常一直在发生.我似乎没有发现"主要"代码有什么问题(见下文),我觉得我已经尝试了一切.有什么可能导致这个的任何线索?
import java.sql.*;
public class DBTesterApp
{
private …Run Code Online (Sandbox Code Playgroud) 我试图通过拼凑示例来在线学习教程.我觉得这应该是播放mp3文件.我正在使用Chrome浏览器,它是最新的.我在控制台上没有任何错误.我不确定我需要更改或添加以使其工作.
<html>
<head>
<script type="text/javascript">
var context;
var sound1Buffer = null;
var url = 'https://dl.dropboxusercontent.com/u/1957768/SrtV2.mp3';
function init(){
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();
}
catch(e) {
alert("web Audio api is not supported!");
}
}
window.addEventListener('load', init, false);
function loadDogSound(url){
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = 'arrayBuffer';
//decode asynchronously
request.onload = function(){
context.decodeAudioData(request.response, function(buffer){
sound1Buffer = buffer;
}, onError);
}
request.send();
}
function playSound(sound1Buffer){
var source = context.createBufferSource();
source.sound1Buffer = sound1Buffer;
source.connect(context.destination); …Run Code Online (Sandbox Code Playgroud) javascript ×5
derby ×2
java ×2
arrays ×1
console.log ×1
function ×1
html ×1
html5 ×1
html5-audio ×1
react-hooks ×1
react-native ×1
reactjs ×1
return-value ×1
sqlexception ×1
use-state ×1
webpack ×1