小编Ada*_*Lee的帖子

Babel NodeJS ES6:SyntaxError:意外的令牌导出

我正在尝试使用 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)

javascript node.js ecmascript-6

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

Android:用于设置 NestedScrollView 最大高度的自定义类不起作用(没有滚动条)

我正在创建一个自定义类来设置 a 的最大高度NestedScrollView,基于此 StackOverflow 问题中提供的答案:

如何在 Android 中为 NestedScrollView 设置最大高度?

但是,当我MaxHeightNestedScrollViewactivity_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)

java android scrollview android-nestedscrollview

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

Firebase Javascript + P5.js:异步函数阻碍了重绘画布

我正在尝试创建一个应用程序,通过从存储圆圈的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)

html javascript processing firebase p5.js

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

Kotlin:如何获取短信的发件人电话号码

我正在尝试读取用户的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

sms android kotlin

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

Android:如何将 HTML 字符串转换为 Spanned 以在 TextView 中显示(必须适用于 API &lt; 24)

对于我的应用程序,我需要将包含 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)

string algorithm android kotlin

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

Android:隐蔽类型;无法将 android.preference.Preference 转换为 androidx.preference.SeekBarPreference

我正在尝试从我的应用程序设置 (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)

java android android-layout build.gradle

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

Android Kotlin:需要上下文但找到字符串

我正在尝试创建一种安排通知的方法。在该方法中,我初始化了一个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 kotlin

5
推荐指数
2
解决办法
1435
查看次数

读取 Microsoft Word 文档时出现 Android Apache POI 错误:org.apache.xmlbeans.SchemaTypeLoaderException 无法解析句柄类型

我正在尝试在我的 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 ms-word docx apache-poi kotlin

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

Android:警报未通过 AlarmManager 触发

我正在编写一个简单的 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)

java android alarmmanager kotlin

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

Docx4J (Android):如何读取 Word 文档中页眉和页脚的内容

我正在尝试使用 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)

java android docx4j kotlin

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