我想从Date
对象中获取当前的小时,分钟和秒.
这是我的代码:
Date date = new Date();
int hour = date.getHours();
Run Code Online (Sandbox Code Playgroud)
但我得到一种错误,这getHours()
部分不起作用.我得到了一个"不推荐使用Data类型的方法getHours()".这意味着什么,我如何得到小时,分钟和秒?
我在我的Github项目中添加了一个项目站点.但有些照片没有在网站上显示.
Img代码:
<img src="img/screenshot2.PNG" class="img-responsive" alt=""> </div>
Run Code Online (Sandbox Code Playgroud)
文件夹结构(img是一个文件夹):
img
Screenshot2.png
index.html
Run Code Online (Sandbox Code Playgroud)
我试过.png
和.PNG
(一些早期的SO答案建议)并且没有一个工作
有解决方案吗
我收到一个[Dagger/MissingBinding]
错误,我不知道为什么会出现这个错误。
这是完整的错误堆栈:
错误:[Dagger/MissingBinding] java.io.File 不能在没有 @Inject 构造函数或 @Provides-annotated 方法的情况下提供。java.io.File 注入 service.KeyStoreService(keyStoreFile) service.KeyStoreService 注入 di.Module.WalletRepositoryModule.getWalletRepository(..., keyStoreService) repository.WalletRepositoryInterface 提供在 di.component.ApplicationComponent.getWalletRepository()
以下其他入口点也依赖于它: dagger.android.AndroidInjector.inject(T) [di.component.ApplicationComponent ? di.Module.BindModule_BindStartModule.StartActivitySubcomponent] dagger.android.AndroidInjector.inject(T) [di.component.ApplicationComponent ? di.Module.BindModule_BindAddWalletActivity.AddWalletActivitySubcomponent]
KeyStoreService 类:
public class KeyStoreService implements KeyStoreServiceInterface {
private final KeyStore keyStore;
@Inject
public KeyStoreService(File keyStoreFile) {
keyStore = new KeyStore(keyStoreFile.getAbsolutePath(), Geth.LightScryptN, Geth.LightScryptP);
}
}
Run Code Online (Sandbox Code Playgroud)
WalletRepositoryModule 类:
@Module
public class WalletRepositoryModule {
@Provides
@ApplicationScope
WalletRepositoryInterface getWalletRepository(SharedPreferencesHelper sharedPreferencesHelper, KeyStoreService keyStoreService){
return new WalletRepository(sharedPreferencesHelper, keyStoreService);
}
}
Run Code Online (Sandbox Code Playgroud)
应用组件类:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class, …
Run Code Online (Sandbox Code Playgroud) 我正在使用Google静态地图来获取Android中的图像(在ImageView中显示).以下是我获取图片的方法:
https://maps.googleapis.com/maps/api/staticmap?center=New+york,NY&zoom=13&size=300x200&maptype=roadmap%20&markers=color:red%7CNew+york,NY
Run Code Online (Sandbox Code Playgroud)
哪个生成此图像:
但是,我想摆脱"谷歌"和"地图数据@ 2016谷歌",以及像"布鲁克菲尔德广场"和"纽约证券交易所"这样的地方.
您可以删除所有标签,style=feature:all|element:labels|visibility:off
如下所示:
https://maps.googleapis.com/maps/api/staticmap?center=New+york,NY&zoom=13&size=300x200&maptype=roadmap%20&markers=color:red%7CNew+york,NY&format=png&style=feature:all|element:labels|visibility:off
Run Code Online (Sandbox Code Playgroud)
但是除了照片底部的标签之外,它会删除所有内容.
编辑:
我发现了如何摆脱所谓的"兴趣点",但两个底部标签仍然存在.
https://maps.googleapis.com/maps/api/staticmap?center=New+york,NY&zoom=13&size=300x200&maptype=roadmap%20&markers=color:red%7CNew+york,NY&format=png&style=feature:poi|element:labels|visibility:off
Run Code Online (Sandbox Code Playgroud)
甚至可以删除它们吗?
我不明白如何解决这个错误。在尝试将片段添加到我的应用程序并使用 Dagger 进行 DI 后,我收到此错误。这是错误堆栈:
错误:[Dagger/IncompatifiableScopedBindings] di.component.ApplicationComponent (unscoped) 可能不引用作用域绑定:@Provides @di.ApplicationContext @di.ApplicationScope android.content.Context di.Module.ApplicationContextModule.getApplicationContext(application.MyApplication) @Provides @di.ApplicationScope android.content.SharedPreferences di.Module.SharedPreferencesModule.getSharedPreferences(@di.ApplicationContext android.content.Context) @Provides @di.ApplicationScope service.KeyStoreServiceInterface di.Module.KeyStoreModule.getKeyStoreService(@Named("KEY_STORE_FILE") ) java.io.File) @Provides @di.ApplicationScope repository.SharedPreferencesHelper di.Module.SharedPreferenceHelperModule.getSharedPreferencesHelper() @Provides @di.ApplicationScope service.CoinmarketcapService di.Module。CoinmarketcapModule.getCoinmarketcapService(com.google.gson.Gson, okhttp3.OkHttpClient) @Provides @di.ApplicationScope com.google.gson.Gson di.Module.GsonModule.getGson() @Provides @di.ApplicationScope okhttp3.OkHttpClient di.Module .OkHttpModule.getOkHttpClient() @Provides @di.ApplicationScope repository.WalletRepositoryInterface di.Module.WalletRepositoryModule.getWalletRepository(repository.SharedPreferencesHelper, service.KeyStoreService)SharedPreferencesHelper, service.KeyStoreService)SharedPreferencesHelper, service.KeyStoreService)
这是我的 ApplicationComponent 类:
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
AndroidInjectionModule.class,
BindModule.class,
AndroidSupportInjectionModule.class,
OkHttpModule.class,
GsonModule.class,
CoinmarketcapModule.class,
WalletRepositoryModule.class})
@SuppressWarnings("unchecked")
public interface ApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication);
ApplicationComponent build(); …
Run Code Online (Sandbox Code Playgroud) 我在一个方法中有 2 个可完成项,例如:
completable1.doSomething()
.andThen(completable2.doSomethingElse())
Run Code Online (Sandbox Code Playgroud)
我想通过使用 Mockito 并在第一个可完成项中返回错误来测试它。这是我的原始方法:
public Completable updateQuestion(Question question){
return gameRepositoryType.updateQuestion(question)
.andThen(gameRepositoryType.getGameById(question.getqId())
.map(GAME_MAPPER)
.flatMapCompletable(gameRepositoryType::updateGame))
.observeOn(AndroidSchedulers.mainThread());
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
@Test
public void updateQuestionError(){
when(gameRepositoryType.updateQuestion(question)).thenReturn(Completable.error(error));
when(question.getqId()).thenReturn(FAKE_QID);
when(gameRepositoryType.getGameById(FAKE_QID)).thenReturn(Single.just(game));
when(gameRepositoryType.updateGame(game)).thenReturn(Completable.complete());
interactor.updateQuestion(question)
.test()
.assertNotComplete()
.assertError(error);
verify(gameRepositoryType).updateQuestion(question); //this is called in test
verify(question,never()).getqId(); //this is called in test
verify(gameRepositoryType,never()).getGameById(FAKE_QID); //this is called in test
verify(gameRepositoryType,never()).updateGame(game); //this is NEVER called in test
}
Run Code Online (Sandbox Code Playgroud)
在测试方法结束时的验证中,我期望在第一个可完成的发出错误后,最后 3 个验证应该成功运行,即verify()
永远不应调用最后 3 个验证。
但是我可以看到,即使gameRepositoryType.updateQuestion(question)
发出错误,也调用了所有方法。这是为什么?
andThen()
如果第一个可完成的发出错误,不应该永远不会被调用吗?
用图片来解释最容易,所以就在这里。这是它现在的样子:
我试图让所有 JButton 的大小相同,即完全垂直填充 BoxLayout。
这是我的代码:
public class TestarBara extends JFrame implements ActionListener{
JButton heyy;
public static void main(String[] args){
new TestarBara();
}
JPanel panel = new JPanel();
JPanel panel2 = new JPanel();
public TestarBara(){
super("knapparnshit");
panel.setLayout(new GridLayout(3,3,2,2));
for(int x=1; x < 10; x++){
String y = Integer.toString(x);
JButton button = new JButton(y);
button.addActionListener(this);
panel.add(button);
}
add(panel, BorderLayout.CENTER);
JButton b1 = new JButton("this");
JButton b2 = new JButton("does");
JButton b3 = new JButton("not");
JButton b4 = new JButton("work");
panel2.setLayout(new BoxLayout(panel2, …
Run Code Online (Sandbox Code Playgroud) 我为我的android应用程序编写了一个简单的Encryption and Decryption助手类,以安全地加密和存储字符串。
它由一个单独的静态公共方法进行加密,然后调用一个私有静态方法对已加密的消息进行解密并返回。我以这种方式编写了该方法,以检查加密/解密后消息是否完整。
我用String编写了一个简单的JUnit测试,并在将其发送到Crypto加密方法之前和之后对String调用了AssertEquals。
我从运行测试中得到以下错误:
javax.crypto.AEADBadTagException: Tag mismatch!
Run Code Online (Sandbox Code Playgroud)
错误堆栈:
at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:571)
at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1046)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:983)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:845)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at util.Crypto.decrypt(Crypto.java:94)
at util.Crypto.encrypt(Crypto.java:64)
at com.example.ali.meappley.CryptoTest.encryptAndDecryptTest(CryptoTest.java:29)
Run Code Online (Sandbox Code Playgroud)
我是密码学的新手,但是我读到了不同的stackoverflow答复,但找不到任何帮助。一些用户建议在致电cipher.update(someByteArray)
之前先打电话,cipher.doFinal(someByteArray)
但我无法使其正常运行。有什么建议么?
这是我的帮手课
public class Crypto {
//public methods
//public static encrypt method
public static String encrypt(String messageToEncrypt, @Nullable byte[] associatedData) throws NoSuchPaddingException,
NoSuchAlgorithmException,
InvalidAlgorithmParameterException,
InvalidKeyException,
BadPaddingException,
IllegalBlockSizeException {
byte[] plainBytes = messageToEncrypt.getBytes();
/////////////////////////////////////////////////////////////////
SecureRandom secureRandom = new SecureRandom();
byte[] key = new byte[16];
secureRandom.nextBytes(key);
SecretKey secretKey = new …
Run Code Online (Sandbox Code Playgroud) 我在启动Android studio时遇到此错误:
Error:Unable to find method 'org.gradle.api.tasks.Sync.getInputs()Lorg/gradle/api/internal/TaskInputsInternal;'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)>Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version …
Run Code Online (Sandbox Code Playgroud) 我有以下代码,想知道是否有任何方法可以将以下代码放入for
循环中,这样它就不会像我在我的代码中做了几次一样长
if (Q1o1.equals("null")){
button1.setVisibility(View.INVISIBLE);
}else{
button1.setVisibility(View.VISIBLE);
button1.setText(Q1o1);
}
if (Q1o2.equals("null")){
button2.setVisibility(View.INVISIBLE);
} else{
button2.setVisibility(View.VISIBLE);
button2.setText(Q1o2);
}
if (Q1o3.equals("null")){
button3.setVisibility(View.INVISIBLE);
} else{
button3.setVisibility(View.VISIBLE);
button3.setText(Q1o3);
}
if (Q1o4.equals("null")){
button4.setVisibility(View.INVISIBLE);
} else{
button4.setVisibility(View.VISIBLE);button4.setText(Q1o4);
}
if (Q1o5.equals("null")){
button5.setVisibility(View.INVISIBLE);
} else{
button5.setVisibility(View.VISIBLE);
button5.setText(Q1o5);
}
if (Q1o6.equals("null")){
button6.setVisibility(View.INVISIBLE);
} else{
button6.setVisibility(View.VISIBLE);
button6.setText(Q1o6);
}
if (Q1o7.equals("null")){
button7.setVisibility(View.INVISIBLE);
} else{
button7.setVisibility(View.VISIBLE);
button7.setText(Q1o7);
}
Run Code Online (Sandbox Code Playgroud)
每个 if 语句都会检查需要作为按钮文本的相关变量是否不为空,然后将其隐藏或将该变量放在按钮内并显示按钮。如何为每个循环使用不同的变量进行 for 循环?
我在这一行收到“无法解析方法”错误:
AndroidInjection.inject(this);
Run Code Online (Sandbox Code Playgroud)
我正在尝试注入一个片段。这是整个班级:
public class ShowWalletFragment extends BaseFragment {
@Inject
ShowWalletViewModelFactory showWalletViewModelFactory;
ShowWalletViewModel showWalletViewModel;
private Wallet wallet;
private static final String TITLE_BALANCE = "Balance";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
//butterknife bind
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
showWalletViewModel = ViewModelProviders.of(this, showWalletViewModelFactory).
get(ShowWalletViewModel.class);
}
@Override
public void onAttach(Context context) {
AndroidInjection.inject(this);
super.onAttach(context);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么它不能解决“这个”?有什么建议?如果您需要我的应用程序中的更多代码,请告诉我。
编辑1:
implementation 'com.google.dagger:dagger:2.19'
annotationProcessor 'com.google.dagger:dagger-compiler:2.19'
implementation 'com.google.dagger:dagger-android:2.19'
implementation 'com.google.dagger:dagger-android-support:2.19'
annotationProcessor …
Run Code Online (Sandbox Code Playgroud) 我在布局中添加了一个工具栏,现在运行时出现此错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/mainactivity.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #2: Error inflating class android.support.design.widget.AppBarLayout
Run Code Online (Sandbox Code Playgroud)
这是我的活动布局:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/appbar"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的应用栏布局:
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_bar"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
在我的活动onCreate()中:
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setTitle(getTitle());
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么。有什么建议么?
我有一个功能Javascript
,我需要每5秒钟重复一次.
这是简单的代码:
function myFunk() {
$('body').addClass('polyonloaded');
setTimeout(myFunk, 5000);
}
myFunk();
Run Code Online (Sandbox Code Playgroud)
它运行一次该功能,不再重复它.我的代码出了什么问题?
android ×8
java ×4
dagger-2 ×3
dagger ×2
swing ×2
androidx ×1
boxlayout ×1
cryptography ×1
date ×1
encryption ×1
for-loop ×1
function ×1
github ×1
github-pages ×1
google-maps ×1
gradle ×1
html ×1
image ×1
javascript ×1
jbutton ×1
jquery ×1
mockito ×1
rx-java ×1
rx-java2 ×1
time ×1