小编Ale*_*avo的帖子

char* - 为什么指针中没有地址?

我有一个基本的问题,char*我不明白

char* aString = "Hello Stackoverflow";
Run Code Online (Sandbox Code Playgroud)

指针指向字符链的第一个字符.

cout << *aString; // H
Run Code Online (Sandbox Code Playgroud)

但为什么整个字符串都保存在指针中?

cout << aString //Hello Stackoverflow
Run Code Online (Sandbox Code Playgroud)

我希望有一个地址,不是指针中保存的地址吗?"Hello Stackoverflow"的地址在哪里?

任何帮助非常感谢

c++

6
推荐指数
2
解决办法
317
查看次数

Rasa NLU 背后的算法是什么?

我看到 Rasa NLU 使用 MITIE 和 spaCy,但谁能解释一下他们如何使用它以及背后的算法?

rasa-nlu rasa nlu

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

了解BufferedReader在Java中的工作方式

关于BufferedReader如何工作的非常基本的问题。给定字符串/短语,我想从其中包含很多文本的文件中查找并打印它。

在Java中使用BufferedReader对此主题进行了一些研究,这是最接近的结果。虽然不能完全解决我的问题。

因此,有了这些信息,为什么以下代码会终止?

public class MainApp {

String line = null;
String phrase = "eye";

try {
    File file = new File("text.txt");
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);

    while((line = br.readLine()) != null) {
        if (line.equals(phrase) {
            System.out.println(line);
           }
        }

    br.close();

} catch (Exception e) {
   e.printStackTrace();
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

我对这个区块应如何运作的了解:

  • while循环遍历文本的每一行,直到条件不再成立为止
  • 每行都存储在BufferedReader中
  • 循环一直工作到满足if(line.equals(phrase)的条件 。
  • 打印找到的词组。

为什么我认为它可能 不会 工作:

  • readlines不会作为字符串存储在BufferedReader中(因此无法进行比较)

  • 错误的逻辑(很可能是if语句)

为了简单起见,让我们假设“ text.txt”充满了非常长的传说ipsum,并且在其中间的某个地方加上了一个“ eye”字。

问题到底在哪里?(如果可能的话,请不要提供完整的代码解决方案,为了练习,我很乐意亲自完成编码工作)。

java filereader bufferedreader

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

Android 低功耗蓝牙获取对特定请求的响应

使用 Gatt 与 BLE 设备进行通信时,我不太明白。根据这个:https : //developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback)

BluetoothGatt gatt = device.connectGatt(context,true,new BluetoothGattCallback(){....})
Run Code Online (Sandbox Code Playgroud)

我可以连接到一个 BLE 设备并给它一个回调对象,以便在 onCharacteristicRead 和 onCharacteristicWrite 之类的东西上得到通知

我没有得到的是哪个写入对应哪个读取回调?

此方法签名是:

public void onCharacteristicRead (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
public void onCharacteristicWrite (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
Run Code Online (Sandbox Code Playgroud)

所以如果我这样做:

BluetoothGattCharacteristic char = gatt.getService(UART_SERVICE_UUID).getCharacteristic(UART_TX_CHARACTERISTIC_UUID);
char1.setValue("command1");
gatt.writeCharacteristic(char);
char1.setValue("command2");
gatt.writeCharacteristic(char);
Run Code Online (Sandbox Code Playgroud)

在 onCharacteristicRead 回调中,我怎么知道characteristic.getStringValue() 是用于command1 还是command2?

谢谢!

android bluetooth bluetooth-lowenergy gatt

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

Spring Boot OAuth2:如何检索用户令牌信息详细信息

我正在关注https://spring.io/guides/tutorials/spring-boot-oauth2/,到目前为止一切正常。实际上,我什至设法将Google Oauth也作为第二个Auth提供程序。现在,我试图从后端的令牌信息端点中读取信息,以使其与本地数据库同步并调整输出。但是我在某种程度上努力检索信息。

本教程在某个时候创建​​了该端点:

@RequestMapping("/user")
public Principal user(Principal principal) {
    return principal;
}
Run Code Online (Sandbox Code Playgroud)

当被调用时,这为我正确显示(成功登录后)

{
    "authorities": [...],
    "details": {...},
    "authenticated": true,
    "userAuthentication": {
        "authorities": [...],
        "details": {
            "email": "foo@bar.com",
            "name": "Foo Bar",
            "id": "12345674890000"
        },
        "authenticated": true,
        "principal": "12345674890000",
        "credentials": "N/A",
        "name": "12345674890000"
    },
    "oauth2Request": {},
    "clientOnly": false,
    "credentials": "",
    "principal": "12345674890000",
    "name": "12345674890000"
}
Run Code Online (Sandbox Code Playgroud)

因此,Spring Boot安全性可以某种方式获取正确的信息。现在,我正在尝试构建一个Interceptor(基本功能正常,在每个请求上都调用拦截器)来处理此信息。我正在努力获取例如电子邮件地址。我找到了这个答案,但它指的是Spring Boot的旧版本,并且只是链接到新的Interface,但是我想知道是否需要它(对于我认为的简单用例,它看起来也很复杂)。什么是/user在我的spring应用程序中从此端点获取信息而不实际调用我自己的端点来检索信息的最佳方法?

我唯一要领取的是通过SecurityContextHolderprincipal id和其他对我没有帮助的东西。我实际上没有检索到例如电子邮件地址。

java spring oauth spring-security spring-boot

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

有没有办法找出针对智能屏幕设备优化的动作列表?

我想从智能屏幕设备上运行的其他操作的外观中学习.所以我想找到经过优化的操作,以便与智能屏幕设备配合使用.

有没有办法以某种方式搜索https://assistant.google.com/explore这些类型的操作?

smartscreen actions-on-google dialogflow-es

5
推荐指数
0
解决办法
69
查看次数

如何在安卓设备上制作 KeyDown 和 KeyUp?

我有个问题。

我正在Android 设备上制作按键动态应用程序。

现在,我使用度量字符串和EditText. 我想抓住KeyDownKeyUp在软件键盘上事件。

我的问题是,使用 Java 在 Android 上捕获KeyUpKeyDown使用的最佳方法是什么?如果EditText是一个不错的选择?如果它有方法来捕捉任何按键?

在此处输入图片说明

编辑

我想从上面的字符串中检测键并测量按下它的时间(例如开始测量KeyDown和停止KeyUp)。如果可能的话,我想阻止我的test string(它的9RJhl6aH0n,就像我的屏幕)中没有提到的其他键

编辑2

到目前为止我取得的成就是这样的,但是default当我编码 line: 时,我的应用程序崩溃了measureText.setText("")。它工作得很好,但仍然不会触发KeyDown(或KeyPress)。这些方法仅在KeyUp用户输入字母时运行。顺序很重要!

measureText.addTextChangedListener(new TextWatcher(){
        @Override
        public void afterTextChanged(Editable arg0) {
            switch(measureText.getText().toString()){
                case "9":
                    break;
                case "9R":
                    break;
                case "9RJ":
                    break;
                case "9RJh":
                    break;
                case "9RJhl":
                    break;
                case "9RJhl6":
                    break;
                case "9RJhl6a":
                    break;
                case …
Run Code Online (Sandbox Code Playgroud)

java android biometrics

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

从socket获取地址族.Linux的

我想为Linux Socket API编写一个C++包装器.在socket()ctor中请求地址族(AF).我不想再次在connect()签名中要求AF,因为它已经在socket的构造函数中给出了.那么如何从现有插座中获取AF?

c c++ linux network-programming

4
推荐指数
2
解决办法
1689
查看次数

ClassCastException:org.springframework.orm.jpa.EntityManagerHolder无法强制转换为org.springframework.orm.hibernate5.SessionHolder

我尝试创建简单的用户登录和注册页面.但我无法使用服务方法创建用户.我有一个创建新用户的服务.

@Service
public class LocalUserDetailsService implements UserService {

//...

@Transactional
@Override
public User registerNewUserAccount(UserDto userDto) throws EmailExistsException {
    System.out.println("registerNewUserAccount called");
    if (emailExist(userDto.getEmail())) {
        throw new EmailExistsException(
                "There is an account with that email adress: "
                + userDto.getEmail());
    }

    return createUser(userDto);
}

private User createUser(UserDto userDto) {
    User user = new User();
    user.setEmail(userDto.getEmail());
    user.setPassword(passwordEncoder.encode(userDto.getPassword()));
    user.setEnabled(userDto.isEnabled());
    Set<Role> roles = new LinkedHashSet<>();

    userDto.getRoles().forEach((roleDto) -> {
        roles.add(roleDao.getOrInsert(roleDto.getName()));
    });

    user.setRoles(roles);

    return userDao.insert(user);
}
}
Run Code Online (Sandbox Code Playgroud)

registerNewUserAccount(UserDto userDto)在2个地方叫方法.1)在启动时,我将此方法称为创建初始用户.

@Component
Run Code Online (Sandbox Code Playgroud)

公共类DatabaseFillerOnStartup实现ApplicationListener {

@Autowired
private UserService userService; …
Run Code Online (Sandbox Code Playgroud)

java hibernate dependency-injection spring-mvc spring-boot

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

Wear OS 上的 Jetpack Compose 中的 BasicTextField 问题

我是 Compose 新手,在 Wear OS 上输入文本字段时遇到问题。问题是我无法像 Android 上那样使用软键盘。另外,当我尝试在 XML 中实现相同的布局时,它成功了。因此,当我点击输入文本字段时,键盘会弹出然后隐藏。当我再次点击时 - 键盘弹出并保持打开状态,但如果我尝试输入任何文本 - 输入字段(键盘本身)中不会出现任何内容,尽管输入的文本正在传递到 UI 上的输入文本字段。

以下是当我点击输入文本字段打开键盘时在模拟器上的日志中得到的内容:

2021-11-24 09:44:36.569 W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
2021-11-24 09:44:36.571 W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
2021-11-24 09:44:36.649 W/RecordingIC: requestCursorUpdates is not supported
Run Code Online (Sandbox Code Playgroud)

这是我在真实设备上得到的结果:

2021-11-24 09:35:39.783 W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
2021-11-24 09:35:39.872 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: setComposingRegion on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: endBatchEdit on inactive …
Run Code Online (Sandbox Code Playgroud)

android wear-os android-jetpack-compose compose-wear

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