小编476*_*ick的帖子

Espresso - TextView包含String

很简单,我怎么说如果一个给定TextView包含一个特定的字符串Espresso.

相当于: myStrings.contains("Subby");

android android-espresso

39
推荐指数
3
解决办法
2万
查看次数

MVP与MVVM - 为什么?

当我使用WinForm时,我正在使用MVP.但是当我开始使用WPF或Silverlight时,我转向了MVVM.

我注意到的唯一事情是,由于强大的绑定,我们不需要在MVVM模式中同步View和ViewModel之间的数据.

我的问题是:

1)绑定(这有助于我们不手动同步View和ViewModel)使用MVVM的唯一优势是什么?

2)MVVM相对于MVP还有其他优势吗?有什么区别?

3)下面的代码是MVVP模式还是MVVM或两者兼而有之?

interface IView {

  void ShowMessage(string message);

}

class View : IView {
    public void ShowMessage(string message){
              MessageBox.Show(this, message);
    }
}

class ViewModel{

private IView view;

public ViewModel(IVew view){

  this.view = view;

}

........

view.ShowMessage("This is a msg");

}
Run Code Online (Sandbox Code Playgroud)

mvp design-patterns mvvm

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

Rest Assured:JSON路径主体与双打不匹配

我正在尝试使用Rest Assured测试API.当我检查double值时有一个AssertionError.

检查双精度的代码:

given().body(getTest()).contentType("application/json\r\n").
            when()
            .port(port)
            .basePath("/fff/test")
            .post("insert")
            .then()
            .assertThat()
            .statusCode(200)
            .body("versie", equalTo(11.0));
Run Code Online (Sandbox Code Playgroud)

这是输出:

java.lang.AssertionError: 1 expectation failed.
JSON path versie doesn't match.
Expected: <11.0>
  Actual: 11.0
Run Code Online (Sandbox Code Playgroud)

当我用.body更改行时:

.body("versie", equalTo(""+11.0));
Run Code Online (Sandbox Code Playgroud)

输出是:

java.lang.AssertionError: 1 expectation failed.
JSON path versie doesn't match.
Expected: 11.0
  Actual: 11.0
Run Code Online (Sandbox Code Playgroud)

有谁知道我怎么解决这个问题?因为我真的不知道如何解决这个问题.

编辑
JSON:

{ 
  "id": 1,
  "naam": "Test X",
  "versie": 11.0
}
Run Code Online (Sandbox Code Playgroud)

java rest junit json rest-assured

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

Java String/Char charAt()比较

我已经看到了您可以使用该charAt()方法进行的各种比较.

但是,我真的不能理解其中的一些.

String str = "asdf";
str.charAt(0) == '-'; // What does it mean when it's equal to '-'?


char c = '3';
if (c < '9') // How are char variables compared with the `<` operator?
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

java comparison char charat

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

OneSignal Android NotificationOpenedHandler - 启动活动

尝试从Parse迁移到OneSignal,我被困在如何在用户点击推送通知后启动新的Activity.我的处理程序正在运行,日志显示文本,问题似乎是如何从我的推送打开处理程序中获取对应用程序上下文的访问权限.示例代码含糊不清,getApplicationContext()如果没有先做其他事情就行不通.

我发现的一篇与OneSignal无关的帖子建议扩展Application类以获取对应用程序上下文的访问权限.这没有产生任何语法错误,但我的应用程序崩溃.

码:

package com.linkedresponder.onesignal;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.onesignal.OSNotificationAction;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OneSignal;

import org.json.JSONObject;

class NotificationOpenHandler extends Application implements OneSignal.NotificationOpenedHandler {
    // This fires when a notification is opened by tapping on it.
    private Context mContext;
    @Override
    public void onCreate() {
        this.mContext = getApplicationContext();
    }
    @Override
    public void notificationOpened(OSNotificationOpenResult result) {
        OSNotificationAction.ActionType actionType = result.action.type;
        JSONObject data = result.notification.payload.additionalData;
        String customKey;

        if (data != null) …
Run Code Online (Sandbox Code Playgroud)

java android

7
推荐指数
2
解决办法
6325
查看次数

Android - Sugar ORM拯救崩溃

我正在尝试将Sugar ORM(v 1.3)集成到我的Android应用程序中,并且在尝试保存新创建的实体时我不断遇到崩溃(NullPointerException).

这是我的崩溃......

01-21 06:02:36.012    2856-2856/com.spuddmobile.kel E/AndroidRuntime? FATAL EXCEPTION: main
    Process: com.spuddmobile.kel, PID: 2856
    java.lang.NullPointerException
            at com.orm.SugarRecord.save(SugarRecord.java:109)
            at com.orm.SugarRecord.save(SugarRecord.java:45)
            at com.spuddmobile.kel.Fragments.NewAppFragment._SaveForm(NewAppFragment.java:231)
            at com.spuddmobile.kel.Fragments.NewAppFragment.onMenuItemSelection(NewAppFragment.java:175)
            at com.spuddmobile.kel.Activities.MainActivity.onOptionsItemSelected(MainActivity.java:89)
            at android.app.Activity.onMenuItemSelected(Activity.java:2600)
            at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1012)
            at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
            at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
            at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
            at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:546)
            at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

这是我的AppManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.spuddmobile.kel" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:name="com.orm.SugarApp"
        android:theme="@style/AppTheme" >

        <meta-data …
Run Code Online (Sandbox Code Playgroud)

orm android sugarorm

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

当我第二次打开父片段时,我的Viewpager崩溃了

一些信息: 我有一个片段,其中包含一个包含三个片段的viewpager.我第一次打开这个片段时,viewpager工作正常.我第二次尝试打开这个片段然后崩溃跟随堆栈跟踪

注意:这发生在kitkat 19 API以上,其工作正常

父片段内的ViewPager设置代码

private void setupViewPager(ViewPager viewPager) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        adapter = new ViewPagerAdapter(getChildFragmentManager());
    } else {
        adapter = new ViewPagerAdapter(getFragmentManager());
   }
    adapter.addFrag(fragment1 , "Abc");
    adapter.addFrag(fragment2, "Bcd");
    adapter.addFrag(fragment3, "Cdf");

    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(2);

    myTabs.setupWithViewPager(viewPager);
}
Run Code Online (Sandbox Code Playgroud)

我的viewpager适配器

class ViewPagerAdapter extends android.support.v13.app.FragmentPagerAdapter {
    private final List<android.app.Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public android.app.Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public long getItemId(int position) { …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-viewpager

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

迁移到androidX - 无法导入/查找androidx.databinding.DatabindingUtil

我正在开发Android MVVM应用程序.我只是手动切换到androidx库.这是我的build.gradle中的库:

implementation 'com.google.code.gson:gson:2.8.5'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc02'
implementation 'com.google.android.material:material:1.0.0-rc01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.airbnb.android:lottie:2.5.5'
implementation 'androidx.recyclerview:recyclerview:1.0.0-rc02'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0-rc01'
implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0-rc01'
implementation 'androidx.lifecycle:lifecycle-runtime:2.0.0-rc01'
implementation "androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01"
implementation "androidx.lifecycle:lifecycle-reactivestreams:2.0.0-rc01"
testImplementation "androidx.arch.core:core-testing:2.0.0-rc01"
implementation "androidx.room:room-runtime:2.0.0-rc01"
annotationProcessor "androidx.room:room-compiler:2.0.0-rc01"
implementation "androidx.room:room-rxjava2:2.0.0-rc01"
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
Run Code Online (Sandbox Code Playgroud)

我更改了代码和布局文件中的所有内容,所有导入等.Gradle可以成功构建.

在我的MainActivity中,我有以下代码:

viewModel = ViewModelProviders.of(this).get(MainViewModel.class);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
binding.setVariable(BR.viewModel, viewModel);
binding.setLifecycleOwner(this);
Run Code Online (Sandbox Code Playgroud)

这是我的MainActivity中唯一不会显示它的androidx版本的包:

import android.databinding.DataBindingUtil;

每个其他包装都显示了androidx自己的版本.当我删除导入时,我只能选择android版本,而不是androidx.

我收到错误:binding.setLifecycleOwner(this); 那是因为DatabindingUtil仍然引用android.databinding包而不是 …

android mvvm gradle android-gradle-plugin androidx

5
推荐指数
3
解决办法
6340
查看次数

Espresso onData在视图上执行"加载适配器数据"时出错

我有一个应用程序,有ListView,我想找到LinearLayout,id = order_untake_jijia_listview_jia

在此输入图像描述

代码是:

onData(withClassName(endsWith("ListView")))
            .inAdapterView(allOf(withId(R.id.order_untake_jijia_listview_ll), hasSibling(withText("9.0"))))
            .atPosition(0).onChildView(withId(R.id.order_untake_jijia_listview_jia));
            dataInteraction.perform(ViewActions.click());
Run Code Online (Sandbox Code Playgroud)

但我有错误:

Error performing 'load adapter data' on view '(with id: com.edaixi:id/order_untake_jijia_listview_ll and has sibling: with text: is "9.0")'.
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(is assignable from class: class android.widget.AdapterView and is displayed on the screen to the user)
Target view: "LinearLayout{id=2131493753, res-name=order_untake_jijia_listview_ll, visibility=VISIBLE, width=170, height=50, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, …
Run Code Online (Sandbox Code Playgroud)

java testing android android-espresso

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

在 Android O 中使用 Intent 启用自动填充服务失败

我使用此代码启用启用自动填充服务。

Intent dialogIntent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
        startActivity(dialogIntent);
Run Code Online (Sandbox Code Playgroud)

我得到了下一个例外:

FATAL EXCEPTION: main

Process: com.example.android.autofillframework, PID: 7683
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.autofillframework/com.example.android.autofillframework.app.StandardSignInActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_SET_AUTOFILL_SERVICE }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_SET_AUTOFILL_SERVICE }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1936)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:711)
at …
Run Code Online (Sandbox Code Playgroud)

android android-service android-autofill-manager

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