小编Jaf*_*KhQ的帖子

Java自定义Annotation聚合多个注释

我正在TestCases为我写作RestControllers
每个ControllerTest calss我使用以下注释

@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebConfig.class, TestAppConfig.class})
Run Code Online (Sandbox Code Playgroud)

所以,我决定定义我自己的注释,包含所有这些注释

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebConfig.class, TestAppConfig.class})
public @interface ControllerTest {
}
Run Code Online (Sandbox Code Playgroud)

然后,我只使用了一个注释 ControllerTest classes

@ControllerTest
public class XXControllerTest {
}
Run Code Online (Sandbox Code Playgroud)

在此修改后,测试失败了

java.lang.IllegalArgumentException: WebApplicationContext is required
    at org.springframework.util.Assert.notNull(Assert.java:115)
Run Code Online (Sandbox Code Playgroud)

为了使它再次工作,它需要我添加@RunWith(SpringJUnit4ClassRunner.class)Test class

@ControllerTest
@RunWith(SpringJUnit4ClassRunner.class)
public class XXControllerTest {
}
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么我的@ControllerTest注释在包含注释时不起作用@RunWith(SpringJUnit4ClassRunner.class)@RunWith注释有什么特别之处吗?还是我错过了什么?

PS:我使用相同的方法Spring config classes,他们工作得很好.

java spring unit-testing annotations

15
推荐指数
1
解决办法
4414
查看次数

findViewById在<include> d视图内的LinearLayout上返回null

我不知道这里的错误.我可能会看到一些事情......

布局XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <include
        android:id="@+id/headerInclude"
        android:layout_width="fill_parent"
        android:layout_height="38dp"
        android:layout_gravity="top"
        layout="@layout/header" />

    <LinearLayout
        android:id="@+id/actualView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:layout_weight="1" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:divider="@drawable/dotted_line"
            android:dividerHeight="2dp"
            android:drawSelectorOnTop="false"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" />
    </LinearLayout>

    <include
        android:layout_width="fill_parent"
        android:layout_height="35dp"
        android:layout_gravity="bottom"
        layout="@layout/footer" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

包含的标头XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/headerLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/header_bgr"
    android:orientation="horizontal"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="7dp" >

    <TextView
        android:id="@+id/tvScreenTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.8"
        android:ellipsize="end"
        android:gravity="center|left"
        android:singleLine="true"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffff"
        android:textSize="17sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvScreenSubTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.2"
        android:gravity="center|right"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffff"
        android:textSize="15sp"
        android:textStyle="bold" …
Run Code Online (Sandbox Code Playgroud)

android include nullpointerexception android-linearlayout

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

设备中未调用 BOOT_COMPLETED

我想在设备启动时启动警报,为此我做了以下事情

1)用户权限

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Run Code Online (Sandbox Code Playgroud)

2)在清单文件中添加带有意图操作的接收者

 <receiver
            android:name=".sms.BootReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" >
                </action>

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
Run Code Online (Sandbox Code Playgroud)

3)来源

public class BootReceiver extends BroadcastReceiver {

    private AlarmManager dayAlarmMgr;
    private PendingIntent dayAlarmIntent;
    private NotificationManager mNotificationManager;
    private NotificationCompat.Builder builder;
    private Context context;
    public static final int NOTIFICATION_ID = 2;

    @Override
    public void onReceive(Context context, Intent intent) {

         if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
                    Toast.makeText(context, "FIRED BOOT COMPLETE" , Toast.LENGTH_LONG).show();
           }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码可以在 genymotion 中运行,但不能在真实设备上运行

android android-broadcast android-reboot

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

关闭浮动动作按钮Android

我使用了以下库https://github.com/futuresimple/android-floating-action-button,一切正常.
单击同一菜单上的其中一个按钮后,如何自动关闭菜单?

android floating-action-button

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