小编Nic*_*cks的帖子

无法在null对象上调用方法systemProperty() - android studio和gradle

在构建我的应用程序时,我遇到一个奇怪的异常.

以下是主应用程序文件夹中的项目specificbuild.gradle文件(不在app文件夹中).

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
    }
}

apply plugin: 'java'

dependencies {
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.9.5"
}

allprojects {
    repositories {
        jcenter()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将gradle依赖项更改为1.2.3版本,我可以解决这个问题,它工作正常.但是1.3.0它甚至没有启动构建并且无法在null对象异常上调用方法systemProperty().

classpath'com.android.tools.build:grad:1.2.3'

android studio日志文件中的详细信息显示:---

2015-09-09 15:28:18,211 [120924807]   WARN - nal.AbstractExternalSystemTask - Cannot invoke method systemProperty() on null object 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot invoke method systemProperty() on null object
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
    at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.getUserFriendlyError(BaseProjectImportErrorHandler.java:158)
    at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.getUserFriendlyError(BaseGradleProjectResolverExtension.java:438)
    at …
Run Code Online (Sandbox Code Playgroud)

gradle android-build android-studio android-gradle-plugin

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

为什么'Path.startsWith'行为与'String.startsWith'操作不同 - 即使对于'Path.getFilename'

我使用的是Java版本1.8.0_31.

我试图使用FileVisitor接口递归访问目录树.程序应该打印C:/books文件名以"Ver"开头的所有文件的名称.该目录C:/books有两个以"Ver"开头的文件,Version.yxyVersion1.txt.我尝试过使用file.getFileName().startsWith("Ver")但是返回false.

我错过了什么吗?这是我的代码:

public class FileVisitorTest {

    public static void main(String[] args) {

        RetriveVersionFiles vFiles = new RetriveVersionFiles();
        try {
            Files.walkFileTree(Paths.get("c:", "books"), vFiles);
        } catch (IOException e) {
            // TODO Auto-generated catch block
         e.printStackTrace();
        }
    }
}

class RetriveVersionFiles extends SimpleFileVisitor<Path> {

    public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
        System.out.println(file.getFileName().startsWith("Ver") + " "
              + file.getFileName());
        if (file.getFileName().startsWith("Ver")) {
            //not entering this if block
            System.out.println(file);
        }
        return FileVisitResult.CONTINUE;
   }
}
Run Code Online (Sandbox Code Playgroud)

上面代码的输出是: …

java java.nio.file

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

尝试使用自定义属性时,标记片段找到了意外的名称空间前缀"custom"

我正在关注这个Android开发者页面,以便为应用程序创建自定义属性.一切都很顺利,我也可以编译并查看结果.但是提出问题的部分是IDE.Android Studio抱怨意外的命名空间自定义.有没有办法禁用/隐藏此错误消息?这非常烦人.

但是,即使出现此错误,我也可以编译并运行该应用程序.

在此输入图像描述

我遵循了以下步骤.

1)创建res/values/attrs.xml文件并添加

<?xml version="1.0" encoding="utf-8"?> <resources>
<declare-styleable name="FragArguments">
    <attr name="max_allowed" format="integer"/>
    <attr name="header" format="string"/>
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)

2)尝试在我的mainlayout文件的片段标记中使用

    <LinearLayout xmlns:custom="http://schemas.android.com/apk/res"
                          android:layout_width="fill_parent"
                          android:layout_height="0dip"
                          android:layout_weight="1">
                <fragment android:id="@+id/msg"
                          android:name="org.android.fragment.MessageFragment"
                          custom:max_allowed="85"
                          custom:header="@string/header"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"/>
            </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

3.通过代码覆盖片段的onInflate()方法应用自定义属性

   @Override
    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
        super.onInflate(activity, attrs, savedInstanceState);

        TypedArray typedArray = activity.obtainStyledAttributes(attrs, R.styleable.FragArguments);
        max_allowed = typedArray.getInt(R.styleable.FragArguments_max_allowed, -1);
        header = typedArray.getString(R.styleable.FragArguments_header);
        typedArray.recycle();
    }
Run Code Online (Sandbox Code Playgroud)

android-layout android-studio android-custom-attributes

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