小编Bog*_*iel的帖子

未收到测试事件 - Android Studio

我不知道如何测试,我正在按照教程.我正在尝试运行:

package name.company.sunshine.app.data;

import android.test.AndroidTestCase;

public class TestPractice extends AndroidTestCase {
     /*
       This gets run before every test.
     */
    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testThatDemonstratesAssertions() throws Throwable {
        int a = 5;
        int b = 3;
        int c = 5;
        int d = 10;

        assertEquals("X should be equal", a, c);
        assertTrue("Y should be true", d > a);
        assertFalse("Z should be false", a == b);

        if (b > d) {
            fail("XX should never happen");
        } …
Run Code Online (Sandbox Code Playgroud)

android android-studio

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

rescue_from ActionController :: RoutingError不起作用

我正试图拯救ActionController::RoutingError,我无法让它发挥作用.我尝试了几乎所有我能在网上找到的东西,包括Rails 4中的rescue_from ActionController :: RoutingError.我有错误控制器和错误页面.我开始工作康康舞access deniedRecordNotFound,但我可以解决RoutingError.

对于康康舞我在里面使用它 application_controller.rb

rescue_from CanCan::AccessDenied do
    render template: 'errors/error_403', status: 403
  end
Run Code Online (Sandbox Code Playgroud)

我的路线中有这个:

match "/404", to: "errors#error_404", via: :all
Run Code Online (Sandbox Code Playgroud)

如果我做同样的事情RoutingError它将无法正常工作.

我也试过,match '*path', :to => "errors#error_404"但我得到了错误.

我怎么解决这个问题?

编辑:如果我RoutingError对拒绝访问做同样的事情:

    rescue_from ActionController::RoutingError do
       render template: 'errors/error_404', status: 404
    end
Run Code Online (Sandbox Code Playgroud)

它不会起作用.

ruby-on-rails ruby-on-rails-4

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

添加自定义参数以设计注册 - 未允许的参数

我一直在尝试自定义设计寄存器方法以注册更多参数并更新更多(到目前为止没有运气),但我总是得到Unpermitted parameters:错误.我尝试使用Devisehttps://github.com/plataformatec/devise#strong-parameters 添加额外的注册字段,但我无法克服这一点.

我还考虑过创建一个新表来保存用户id的外键并放入类似的东西user_id, display_name, profile_picture,但是在尝试从同一页面提交所有内容时我会遇到同样的问题(与设计控制器混乱).

您对我如何解决这个问题有什么建议吗?我还有什么要发布的?

的routes.rb

devise_for :users, controllers: { registrations: 'users/registrations' }
Run Code Online (Sandbox Code Playgroud)

用户/ REGC

def create
    build_resource(registration_params)

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        respond_with resource, :location => after_sign_up_path_for(resource)
      end
    else
      clean_up_passwords
      respond_with resource
    end
  end

private
  def registration_paramss
    params.require(:user).permit(:email, :display_name, :terms_of_services, :profile, :password, :password_confirmation)
  end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise ruby-on-rails-3 ruby-on-rails-5

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

如何在ViewPager中使用cursorLoader?

I have a `cursorLoader` which is working fine.
Run Code Online (Sandbox Code Playgroud)

问题是我不使用它像我应该,我从这些数据加载cursorLoaderarrayLists,然后使用列表.

我发现这个教程,展示了如何使用cursorLoader一个viewPager,但我不明白如何真正做到这一点.

http://tumble.mlcastle.net/post/25875136857/bridging-cursorloaders-and-viewpagers-on-android

我有一个片段,看起来像这样:

public class FirstFragment extends Fragment {
    MapView mapView;
    GoogleMap map;
    // Store instance variables
    private String email,about,imagepath,latitude,longitude;
    Button getDirections;

    // newInstance constructor for creating fragment with arguments
    public static FirstFragment newInstance(String email,String about,String imagepath, String latitude, String longitude) {
        FirstFragment fragmentFirst = new FirstFragment();
        Bundle args = new Bundle();
        args.putString("email", email);
        args.putString("about", about);
        args.putString("imagepath", imagepath);
        args.putString("latitude", latitude);
        args.putString("longitude", longitude);
        fragmentFirst.setArguments(args); …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-studio

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

类com.facebook.drawee.view.SimpleDraweeView出错时出错

我正在尝试使用壁画库.我之前也使用它并且它正在工作,但现在,由于某种原因,我得到:

Unable to start activity ComponentInfo{com.example.home.template/com.example.home.template.MainActivity}: android.view.InflateException: Binary XML file line #26: Error inflating class com.facebook.drawee.view.SimpleDraweeView
Run Code Online (Sandbox Code Playgroud)

我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:fresco="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">


<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/profileImage"
        fresco:actualImageScaleType="centerCrop"
        android:layout_width="200dp"
        android:layout_gravity="center_horizontal"
        android:layout_height="200dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的应用程序:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(this);
    }
}
Run Code Online (Sandbox Code Playgroud)

我在我的清单中有它: android:name=".MyApplication"

我遇到的唯一问题是draweeview.我可以做所有其他的事情,比如登录和获取信息.

android facebook fresco

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

有什么可以替换http弃用的方法?

我正在按照教程进行操作,并且我已经批准了很多代码.

ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("name", user.name));
dataToSend.add(new BasicNameValuePair("age", user.age));

HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParamas.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpConnectionParamas.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);

HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS + "Register.php");

try{
    post.setEntity(new UrlEncodedFormEntity(dataToSend));
    client.execute(post);
}catch (Exception e){
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

和另一个返回结果的POST方法

    HttpResponse httpResponse = client.execute(post);

    HttpEntity entity = httpResponse.getEntity();
    String result = EntityUtils.toString(entity);
    JSONObject jObject = new JSONObject(result);
Run Code Online (Sandbox Code Playgroud)

我发现,我可以代替NameValuePair

ContentValues values = new ContentValues();
values.put("name", user.name);
values.put("age", user.age + "");
Run Code Online (Sandbox Code Playgroud)

但我不知道其他人.

android androidhttpclient android-studio

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

如何修改Android 9patch图像的颜色?

我真的不明白如何创建一个9patch图像,但我找到了一个正在处理我的片段的图像.问题是边框外的颜色不是背景的颜色.我尝试将像素的颜色从图像更改为背景的颜色,但生成的图像不再起作用.这是正在工作但颜色错误的图像:

http://i.stack.imgur.com/cJBfV.png

如何更改边框外像素的颜色,或者如何创建看起来像这样的新9patch图像?

android android-studio

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

如何使用 Room Android 插入空字段

我正在尝试尝试并了解 Android 的 Room 持久性库。到目前为止,我已经了解了如何插入内容并查询它们,但现在我尝试使用 2 个构造函数,以便在我不想插入字段时不插入字段。

像这样的东西:

    public ImageData(int id, String name, String title, String description, int locationId) {

 .....

      public ImageData(int id, String name, String title, String description) {
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我没有位置,因此我不想在 int Location 列中插入任何内容。这是实现它的正确方法吗(显然不是因为我收到错误)?

Error:(38, 12) error: Room cannot pick a constructor since multiple constructors are suitable. Try to annotate unwanted constructors with @Ignore.
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,请告诉我。

编辑:

@Entity(primaryKeys = {"id", "name"},
        foreignKeys = @ForeignKey(entity = Location.class,
        parentColumns = "id",
        childColumns = "location_id",
        onDelete=CASCADE))
public class ImageData {

    @NonNull
    public int …
Run Code Online (Sandbox Code Playgroud)

android android-room

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

getGoogleAppid失败/无法上传Android Studio

我有一个应用程序,它获取该位置并将其发送到服务器.我得到以下错误,我不知道它们来自哪里:

 11-05 02:47:11.699 27839-27839/? E/Zygote: MountEmulatedStorage()
11-05 02:47:11.699 27839-27839/? E/Zygote: v2
11-05 02:47:11.719 27839-27839/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
11-05 02:47:12.009 27839-27896/name.company.newapp E/GMPM: getGoogleAppId failed with status: 10
11-05 02:47:12.009 27839-27896/name.company.newapp E/GMPM: Uploading is not possible. App measurement disabled
Run Code Online (Sandbox Code Playgroud)

这是完整的logcat:

 11-05 02:47:11.699 27839-27839/? E/Zygote: MountEmulatedStorage()
11-05 02:47:11.699 27839-27839/? E/Zygote: v2
11-05 02:47:11.699 27839-27839/? I/libpersona: KNOX_SDCARD checking this for 10799
11-05 02:47:11.699 27839-27839/? I/libpersona: KNOX_SDCARD not a persona
11-05 02:47:11.719 27839-27839/? I/SELinux: Function: selinux_compare_spd_ram, SPD-policy is …
Run Code Online (Sandbox Code Playgroud)

android android-location android-studio

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

在 js 文件中使用 sass 变量 create-react-app

我有一些颜色定义的变量到_colors.scss文件中。

$color-succcess: #706caa;
$color-error: #dc3545;
Run Code Online (Sandbox Code Playgroud)

我还想将它们用于一些样式化的 React 组件react-table到我的 js 文件中。

我使用以下文章https://til.hashrocket.com/posts/sxbrscjuqu-share-scss-variables-with-javascript作为参考,还有许多其他人喜欢它,但我无法让它工作。

我从我的 scss 文件中导出颜色:

:export {
  colorSuccess: $color-succcess;
  colorError: $color-error;
}
Run Code Online (Sandbox Code Playgroud)

我将它们导入到我的 js 文件中:

import colors from "../../styles/_colors.scss";

但他们可能没有正确加载。

我如何配置 create-react-app 生成的代码以实现与文章中的人使用 webpack 所做的相同的事情。

javascript sass reactjs create-react-app

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