我想定义一个构建配置文件,我可以在它自己使用gradle脚本中定义的变量:
def someVar = 512
android {
...
buildConfigField 'int', 'SOME_INT_FIELD', someVar
}
Run Code Online (Sandbox Code Playgroud)
但这会产生以下错误:
错误:(25,0)未找到Gradle DSL方法:'buildConfigField()'
可能的原因:
项目"PROJECT"可能正在使用不包含该方法的Gradle版本. 构建文件可能缺少Gradle插件.
我可以使用以下引用:
def someVar = 0
android {
...
buildConfigField 'int', 'SOME_INT_FIELD', '"' + someVar + '"'
}
Run Code Online (Sandbox Code Playgroud)
但这导致BuildConfig中的编译器错误
// Fields from default config.
public static final int SOME_INT_FILED = "512";
Run Code Online (Sandbox Code Playgroud)
所以现在我留下来:
def someVar = 0
android {
...
buildConfigField 'String', 'SOME_INT_FIELD', '"' + someVar + '"'
}
Run Code Online (Sandbox Code Playgroud)
并使用它像:
final int value = Integer.valueOf(BuildConfig.SOME_INT_FIELD);
Run Code Online (Sandbox Code Playgroud)
有没有人有更好的解决方案或我使用buildConfigField错误?
(我也尝试将括号与上述任何可能性结合使用.)
我收到以下警告:
自定义视图com/example/view/adapter/SomeAdapter缺少工具使用的构造函数:(Context)或(Context,AttributeSet)或(Context,AttributeSet,int)
在我的类SomeAdapter中,它扩展了一些扩展ArrayAdapter的BaseAdapter
public class SomeAdapter extends BaseAdapter{}
public abstract class BaseAdapter extends ArrayAdapter<SomeModel>{}
Run Code Online (Sandbox Code Playgroud)
警告存在于具体适配器中,但不存在于抽象BaseAdapter中.在这种情况下有没有人听说过这个警告?
AFAIK Android通过ViewConstructorDetector检查超类的名称来检查类是否正在扩展视图:
private static boolean isViewClass(ClassContext context, ClassNode node) {
String superName = node.superName;
while (superName != null) {
if (superName.equals("android/view/View") //$NON-NLS-1$
|| superName.equals("android/view/ViewGroup") //$NON-NLS-1$
|| superName.startsWith("android/widget/") //$NON-NLS-1$
&& !((superName.endsWith("Adapter") //$NON-NLS-1$
|| superName.endsWith("Controller") //$NON-NLS-1$
|| superName.endsWith("Service") //$NON-NLS-1$
|| superName.endsWith("Provider") //$NON-NLS-1$
|| superName.endsWith("Filter")))) { //$NON-NLS-1$
return true;
}
superName = context.getDriver().getSuperClass(superName);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,我的班级名称与上述模式不符.有谁知道如何修复或抑制此警告?
BaseAdapter中的getView():
@Override
public final View getView(final int position, …Run Code Online (Sandbox Code Playgroud) 在调试/运行我的metro应用程序时,我有一些奇怪的行为.在拖拽期间,屏幕将被刷新.我已经添加了一些功能来阻止绑定属性从刷新时拖拽正在进行中.
但有时应用程序崩溃了,但是我没有抛出一些我可以调试的异常,而是我得到的一个窗口就是打开一个外部即时调试器
SOME_APP.exe [7785]中发生了未处理的win32异常.
(外部调试器不会带来更多信息)
输出说:
SOME_APP.exe中0x05017145(Windows.UI.Xaml.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000088.
我正在使用x64设备.有人听说过这样的问题吗?
在我的Activity(扩展android.support.v7.app.ActionBarActivity)中,我有一个片段,通常包含在我的视图中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fragment
android:name="com.fragments.SomeFragment"
android:id="@+id/fragment_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
这很好用.
但是我决定将这个片段重用为对话框,所以我通过android.support.v4.app.DialogFragment(来自支持的库)扩展它.
没有任何其他更改我得到了例外
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ExampleActivity}: java.lang.IllegalStateException: DialogFragment can not be attached to a container view
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: DialogFragment can not be attached to a container view
at android.support.v4.app.DialogFragment.onActivityCreated(DialogFragment.java:364) …Run Code Online (Sandbox Code Playgroud) android illegalstateexception android-fragments android-dialogfragment android-actionbar-compat
android ×3
adapter ×1
buildconfig ×1
gradle ×1
listadapter ×1
variables ×1
warnings ×1
winapi ×1
windows-8 ×1
xaml ×1