我正在尝试使用 babel 来运行我的 NodeJS 程序,其中包括 ES6 语法和来自 Colyseus 库的导出。但是,当我运行命令时:
babel-node server.js
Run Code Online (Sandbox Code Playgroud)
出现以下错误消息:
export class MyRoom extends colyseus.Room {
^^^^^^
SyntaxError: Unexpected token export
Run Code Online (Sandbox Code Playgroud)
下面是我的 package.json 文件:
{
"name": "app",
"version": "1.0.0",
"description": "a description",
"main": "server.js",
"scripts": {
"test": "babel-node server.js",
"build": "babel-node server.js"
},
"author": "henryzhu",
"license": "ISC",
"dependencies": {
"actionhero": "^19.1.2",
"colyseus": "^0.9.33",
"easytimer.js": "^2.3.0",
"express": "^4.16.3",
"socket.io": "^2.1.0",
"socketio": "^1.0.0",
"uniqid": "^5.0.3"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1"
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我的 server.js 文件:
var …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个自定义类来设置 a 的最大高度NestedScrollView
,基于此 StackOverflow 问题中提供的答案:
如何在 Android 中为 NestedScrollView 设置最大高度?
但是,当我MaxHeightNestedScrollView
在activity_main.xml
代码布局中包含自定义类 ( )时,当里面的 TextView超过定义的最大高度时,不会出现滚动条MaxHeightNestedScrollView
。下面是代码MaxNestedScrollView
:
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
public class MaxHeightNestedScrollView extends NestedScrollView {
private int maxHeight = -1;
public MaxHeightNestedScrollView(@NonNull Context context) {
super(context);
}
public MaxHeightNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MaxHeightNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public int …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个应用程序,通过从存储圆圈的x和y坐标的Firebase数据库中读取信息,将圆圈绘制到画布上.然而,执行下面的代码,根本不产生任何东西,没有圆圈的任何迹象,因为函数drawCricles异步运行,因此命令background(40)
在绘制圆之前清除所有内容.
这是我的代码:
function setup() {
createCanvas(windowWidth, windowHeight);
background(40);
stroke(80);
smooth();
frameRate(60);
}
function drawCircles() {
firebase.database().ref("circles").once("value", function(snapshot) {
var snapshotVal = snapshot.val();
var circleCount = snapshotVal.numCircles;
for (var j = 0; j < circleCount; j++) {
firebase.database().ref("circles" + j).once("value", function(snapshot) {
var snapshotValue = snapshot.val();
fill(143, 2, 2);
ellipse(snapshotValue.xPos, 50, 50);
});
}
});
}
function draw() {
stroke(80);
background(40);
stroke(0);
drawCircles();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试读取用户的SMS消息,并获取这些消息的发件人电话号码。当我尝试通过该"address"
列获取消息发件人的电话号码时,它返回文本对话的电话号码(例如,如果我向电话号码为X的用户发送消息,则该address
列返回X而不是我的电话号码),而不是发送消息的人的电话号码。以下是我的Kotlin代码:
var cursor = contentResolver.query(
Uri.parse("content://sms/"),
null,
null,
null,
null
)
// Retrieve the IDs of the sender's name
var senderID = cursor!!.getColumnIndex("address")
// Iterate through every message
while (cursor!!.moveToNext()) {
var messageSender = cursor.getString(senderID) // Get the sender of the message
System.out.println("---------------------------------------------------------")
System.out.println(messageSender) // Returns phone number of the conversation, not the sender
}
Run Code Online (Sandbox Code Playgroud)
例如:电话号码为123456789的用户向您发送消息。我想检索电话号码123456789。
对于我的应用程序,我需要将包含 span(带有背景颜色)的 HTML 显示为 a Spanned
,以便它可以显示在 a 上TextView
,因为 AndroidTextView
不支持该span
标记。我首先尝试将 转换String
为 a SpannableStringBuilder
,然后从转换的字符串 ( Spanned
) 中检索 HTML 编码的字符串。我需要它在 API 22-23 上工作,因此,我不能简单地使用 fromHTML,因为fromHTML
它不支持span
低于 24 的 API。我正在编写一个名为的函数fromHTML
来完成此操作:
输入示例fromHTML
(输入可以是任何带跨度的字符串):
Not highlighted string<span style=\"background-color: #FF8983\">Highlighted string</span>
not highlighted string <span style=\"background-color: #FF8983\">Highlighted string</span>
Run Code Online (Sandbox Code Playgroud)
下面是我的代码:
private fun fromHtml(source:String):Spanned {
var htmlText:SpannableStringBuilder = source as SpannableStringBuilder;
var htmlEncodedString:String = Html.toHtml(htmlText);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从我的应用程序设置 (preferences.xml) 的布局中检索 SeekBarPreference。但是,当我尝试将 findPreference("font_size") 转换为 SeekBarPreference 时,出现以下错误:
不可转换的类型;无法将 android.preference.Preference 转换为 androidx.preference.SeekBarPreference
下面是与我的设置页面 (MyPreferencesAcitivty.java) 相对应的代码 - 错误发生在这一行 final SeekBarPreference fontSizeSeekBar = (SeekBarPreference) findPreference("font_size");
::
package com.example.myapplication;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.Preference;
import android.widget.EditText;
import androidx.preference.SeekBarPreference;
public class MyPreferencesActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
// …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一种安排通知的方法。在该方法中,我初始化了一个AlarmManager
,这将允许我按需接收 Intent。但是,我的代码中出现以下语法错误:
类型不匹配。必需:找到的上下文:字符串
在以下行:
var alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
Run Code Online (Sandbox Code Playgroud)
下面是我的代码:
package com.example.notificationapp
import android.app.AlarmManager
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.PendingIntent.getActivity
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat.getSystemService
import java.security.AccessController.getContext
import java.util.*
// Channel
class Notification(context:Context, notificationManager: NotificationManager, title:String, description:String, date: Date) {
// Attributes
private lateinit var context:Context;
private var title:String = ""
private var description:String = ""
private lateinit var date:Date;
private lateinit var notificationManager:NotificationManager;
// Initialization
init {
// Download the constructor parameters into …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Android 应用程序中使用 Apache POI,以便我可以读取 Microsoft Word 文件。我正在集成 POIA 库,该库可在 Android ( https://github.com/SUPERCILEX/poi-android )上使用 Apache POI 。但是,当我运行代码并读取 Word 文件时,收到以下错误:
异常:org.apache.xmlbeans.SchemaTypeLoaderException:无法解析句柄 _XY_Q=space|R=space 的类型
下面是我的代码(我在第一行收到错误):
var document = XWPFDocument(uri?.let { contentResolver.openInputStream(it) });
var extractor = XWPFWordExtractor(document);
var documentText = extractor.text; // Retrieve the document's text
Run Code Online (Sandbox Code Playgroud)
在运行时,我有以下代码:
super.onCreate(savedInstanceState)
System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl")
System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl")
System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl")
Run Code Online (Sandbox Code Playgroud)
以下是我的 gradle(项目级):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.60'
repositories {
google()
jcenter()
}
ext {
poiVersion …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个简单的 Android 程序,该程序在应用程序初始化后 15 秒触发警报(播放默认铃声并推送通知)AlarmManager
。下面是我的代码:
MainActivity.java:
package com.example.basicalarmsetter;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
public class MainActivity extends AppCompatActivity {
private int uniqueId = 0;
// Schedules a notification in the future given the delay
@RequiresApi(api = Build.VERSION_CODES.O)
private void scheduleNotification(int matchId, long delay) {
// Construct the PendingIntent which will trigger our alarm to go off
Intent notificationIntent = new Intent();
notificationIntent.setAction("com.example.basicalarmsetter.MatchNotification");
PendingIntent pendingIntent …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Docx4J ( https://github.com/plutext/Docx4j4Android4 ) 来读取 Word 文件的内容。但是,使用以下代码,我的程序仅读取 Word 文件(存储在documentLines
)的正文内容(不读取页眉或页脚)。如何让我的程序读取文件页眉和页脚的内容?
下面是我的代码:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == READ_IN_FILE) { // When a result has been received, check if it is the result for READ_IN_FILE
if (resultCode == Activity.RESULT_OK) { // heck if the operation to retrieve the Activity's result is successful
// Attempt to retrieve the file
try {
var uri = data?.data // Retrieve the file's resource locator …
Run Code Online (Sandbox Code Playgroud) android ×8
kotlin ×6
java ×4
javascript ×2
alarmmanager ×1
algorithm ×1
apache-poi ×1
build.gradle ×1
docx ×1
docx4j ×1
ecmascript-6 ×1
firebase ×1
html ×1
ms-word ×1
node.js ×1
p5.js ×1
processing ×1
scrollview ×1
sms ×1
string ×1