我有两个问题
我尝试了以下操作,但收到错误“不允许引用任何超出范围的变量。无效的变量访问:时刻”
说一下我的功能:
function test(configVariable) {
const variable = config.get(configVariable)
}
Run Code Online (Sandbox Code Playgroud)
测试功能
jest.mock('config', () => ({
default: {
get: () => jest.fn().mockImplementation(() => {
const dDate = moment();
dDate.subtract(1, 'd');
dDate.format('YYYY-MM-DD');
return dDate;
}),
}
}));
Run Code Online (Sandbox Code Playgroud)
有人可以帮我做同样的事情吗?提前感谢您的宝贵时间。
我正在使用 Android 并在创建服务并从主活动线程运行它时遇到以下错误。我确实浏览了与此错误相关的所有线程,但他们看到的错误主要是针对 Activity 任务。以下是错误和代码的详细信息
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.serviceexample/com.example.serviceexample.MyServiceBg}; have you declared this activity in your AndroidManifest.xml?
Run Code Online (Sandbox Code Playgroud)
我确实检查了我的 AndriodManifest.xml,我确实看到了声明的服务
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.serviceexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="ServiceExample"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name=".MyIntentService"
android:exported="false"></service>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyBgService"/>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
主活动.java:
package com.example.serviceexample;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud)