Android Cursor可以返回一个布尔值吗?我查看了文档,但没有相关信息?
如果不是 - 那么是否有另一种方法从SQLite表中获取布尔值?
我有一个简单的方法,采用一般的List参数但由于某种原因,我的IDE(Eclipse)说明它是如何解决的?
我在这里做错了什么
private OnClickListener removeFieldListener(final LinearLayout layout,
List<T> viewList) {
return new OnClickListener() {
@Override
public void onClick(View v) {
int indexToDelete = layout.indexOfChild(v);
}
};
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用旧的facebook连接身份验证来验证我的Android客户端,以获得必要的会话ID和开始使用Facebook的Web服务所需的其他凭据.
我遇到的问题是,当我的Android应用程序启动并尝试加载facebook的登录页面时,同一个登录页面是空白的,它只显示Facebook徽标作为屏幕的标题.
没有可见的登录字段或按钮,无法登录和验证用户.
我试过两个API的一个是facebook连接api for android http://code.google.com/p/fbconnect-android/ 另一个是官方的android facebook sdk建议用来代替前一个我刚才提到https://github.com/facebook/facebook-android-sdk/.
请参阅下面的图片,了解它在我的应用上的样子.

这是使用最新的android sdk facebook的代码:
/**
* Authenticate facebook network
*/
private void authenticateFacebook() {
// TODO: move this away from this activty class into some kind of
// helper/wrapper class
Log.d(TAG, "Clicked on the facebook");
Facebook facebook = new Facebook(OAUTH_KEY_FACEBOOK_API);
facebook.authorize(this, new AuthorizeListener());
}
class AuthorizeListener implements DialogListener{
@Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
Log.d(TAG, "finished authorizing facebook user");
}
@Override
public void …Run Code Online (Sandbox Code Playgroud) 如何在注释中设置值?
我定义了以下注释:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface JsonElement {
int type();
}
Run Code Online (Sandbox Code Playgroud)
以下是在POJO类中使用它的方法
@JsonElement(type=GETTER_METHOD)
public String getUsername{
........................
}
Run Code Online (Sandbox Code Playgroud)
而util类使用反射来检查此方法是否存在JSonElement注释,并检查类型值是什么.
Method methods[] = classObject.getClass().getDeclaredMethods();
JSONObject jsonObject = new JSONObject();
try {
for (int i = 0; i < methods.length; i++) {
String key = methods[i].getName();
System.out.println(key);
if (methods[i].isAnnotationPresent(JsonElement.class) && key.startsWith(GET_CHAR_SEQUENCE)) {
methods[i].getDeclaredAnnotations();
key = key.replaceFirst(GET_CHAR_SEQUENCE, "");
jsonObject.put(key, methods[i].invoke(classObject));
}
}
return jsonObject;
} catch (Exception e) {
e.printStackTrace();
return null;
}
Run Code Online (Sandbox Code Playgroud)
我如何找出type()价值是多少?我可以找到是否存在注释,但我找不到一个方法来找出设置的值 - 如果有的话type().
我收到此错误,说它无法找到与Android插件相关的类路径.使用gradle 1.2.
这是错误:
Could not find method classpath() for arguments [org.gradle.api.plugins:gradle-android-plugin:1.2.1]
Run Code Online (Sandbox Code Playgroud)
这是我的build.gradle档案
//setup external dependency plugins we will use to build a android application
buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.1'
}
}
//apply eclipse plugin
apply plugin: 'eclipse'
//apply android plugin
apply plugin: 'android'
apply plugin: 'maven'
task hello << {
String value = 'wagwan'
println 'Hello world!' + value.toUpperCase()
}
Run Code Online (Sandbox Code Playgroud)
谢谢
编辑:我现在收到的新错误:
FAILURE: Build failed with an exception. …Run Code Online (Sandbox Code Playgroud) 嗨,可以在gradle.properties文件中指定环境变量名称而不是完整路径吗?
我有这样的路径设置:
guardit4jpath=/Users/me/Public/GuardIT_for_Java_5.1
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以像下面这样指定:
guardit4jpath=GuardIt_HOME
Run Code Online (Sandbox Code Playgroud)
举个例子?
我似乎找不到有关如何完成此操作的任何信息?
亲切的问候
[来自未来的注释,2021 年,在底部添加 - 他们缩短了答案]
下面我有一个具有上述结构的项目。
我可以愉快地在应用程序模块内很好地运行 uni 测试,但在 lib 模块上找到的单元测试不会运行,除非我手动右键单击 lib 模块内的 DummyDataTest.java 并单击 Android studio 内的运行单元测试。
有没有办法通过命令行自动运行位于我的 lib 模块中的单元测试?
现有的命令行 ./gradlew testDebug 仅运行位于应用程序模块内的单元测试。
提前致谢
JUnitTestProject
app [module]
src
main
java
de.ivu.junittest.app
DummyModel.java
...
...
test
java
de.ivu.junittest.app
DummyModelTest.java
...
lib [module]
src
main
java
de.ivu.junittest
DummyData.java
...
...
test
java
de.ivu.junittest.app
DummyDataTest.java
...
Run Code Online (Sandbox Code Playgroud) 我正在使用Android Studio 3预览代码并构建一个android kotlin项目,但由于此错误,它似乎无法编译:
:java.lang.Exception:无法在10000毫秒内从守护程序获取响应
无法执行增量编译:无法连接到Kotlin编译守护程序无法连接到kotlin守护程序.使用后备策略.
Run Code Online (Sandbox Code Playgroud)Error:Failed to complete Gradle execution. Cause: Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
这是我的gradle构建文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试模拟最后一个类(默认情况下,kotlin中的所有类都是最终类),并在gradle中添加了以下依赖项:
testImplementation 'junit:junit:4.12'
testImplementation 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.10'
testImplementation "org.mockito:mockito-android:2.13.0"
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation "org.mockito:mockito-core:2.13.0"
//testImplementation 'io.mockk:mockk:1.8'
testImplementation 'org.assertj:assertj-core:3.8.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation "org.mockito:mockito-core:2.13.0"
androidTestImplementation "org.mockito:mockito-android:2.13.0"
androidTestImplementation 'org.mockito:mockito-inline:2.13.0'
androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
Run Code Online (Sandbox Code Playgroud)
该模仿内联应该使您能够模拟最终的kotlin类,因此我使用testImplementation和androidTestImplementation将其添加到我的Java单元测试和仪器测试中
在构建项目时,出现以下错误:
More than one file was found with OS independent path 'mockito-extensions/org.mockito.plugins.MockMaker'
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?如果我删除了类内联的androidTestImplementation,它可以正常编译,但是在运行仪器测试时,我收到了类比错误,说它无法模拟最终类。
嗨,我尝试在我的项目中运行示例检测测试类,但是每次我运行它时,都会出现此错误:
Test running failed: no test results
Empty test suit
Run Code Online (Sandbox Code Playgroud)
这是我的示例测试类
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().context
assertEquals("com.app", appContext.packageName)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我用于测试的gradle构建文件:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.app"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
} …Run Code Online (Sandbox Code Playgroud) android ×8
java ×5
kotlin ×3
gradle ×2
unit-testing ×2
annotations ×1
facebook ×1
generics ×1
junit ×1
mockito ×1
reflection ×1
robolectric ×1
sqlite ×1