我的gradle构建文件中有以下警告
并非所有执行路径都返回值
此检查报告在返回方法结束时缺少groovy return语句
这是该文件中的代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "ac.company.srikar.quickhelpindia"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉这里的问题是什么以及如何摆脱这个警告.
有谁知道为什么会这样?我看到我的应用程序报告了这个崩溃,但我不知道它是什么.
java.lang.NoClassDefFoundError: android.app.ANRManagerProxy
Thread: Binder_3, Exception: java.lang.NoClassDefFoundError: android.app.ANRManagerProxy
at android.app.ANRManagerNative.asInterface(ANRManagerNative.java:30)
at android.app.ANRManagerNative$1.create(ANRManagerNative.java:94)
at android.app.ANRManagerNative$1.create(ANRManagerNative.java:88)
at android.util.Singleton.get(Singleton.java:34) at android.app.ANRManagerNative.getDefault(ANRManagerNative.java:37)
at android.os.MessageLogger.dump(MessageLogger.java:253)
at android.app.ANRAppManager.dumpMessageHistory(SourceFile:38)
at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1176)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:609)
at android.os.Binder.execTransact(Binder.java:351)
at dalvik.system.NativeStart.run(Native Method)
Run Code Online (Sandbox Code Playgroud) crash android noclassdeffounderror stack-trace android-anr-dialog
我有以下情况.
我的活动有一个依赖于Serializable Object的片段.这是我的onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyObject myObj = (MyObj) getIntent().getSerializableExtra("myobj");
if(myObj != null) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.container, MyFragment.newInstance(myObj));
transaction.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
但是在我的Espresso测试中,我无法在创建活动之前将意图传递给活动.我尝试了几种方法的setActivityIntent,但无法弄清楚如何使它工作.
这是我的最后一次尝试:
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.test.ActivityInstrumentationTestCase2;
import org.junit.Before;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
public class MyActivityTest extends
ActivityInstrumentationTestCase2<MyActivity> {
private MyActivity activity;
private MyObject myObj;
public MyActivityTest() {
super(MyActivity.class);
}
@Before
protected void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
myObj …Run Code Online (Sandbox Code Playgroud) 我正试图通过Android Auto显示通知.通知确实显示在我的手机上.但是,它没有在Android Auto模拟器上显示.这是一个媒体应用程序.
automotvie_app_desc.xml:
<automotiveApp>
<uses name="media"/>
</automotiveApp>
Run Code Online (Sandbox Code Playgroud)
这段代码在我的MediaBrowserService班上:
private Notification postNotification(AutoNotificationHelper.Type type) {
Log.d(TAG, "Post Notification");
Notification notification = AutoNotificationHelper.createMenuErrorNotification(
getApplicationContext(), type, mSession);
if (notification != null) {
mNotificationManager.notify(TAG, NOTIFICATION_ID, notification);
}
return notification;
}
Run Code Online (Sandbox Code Playgroud)
这是创建通知的位置:
static Notification createMenuErrorNotification(Context context, Type type,
MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mMetadata = controller.getMetadata();
PlaybackStateCompat mPlaybackState = controller.getPlaybackState();
if (mMetadata == null) {
Log.e(TAG, "MetaData is null");
}
if (mPlaybackState == null) {
Log.e(TAG, …Run Code Online (Sandbox Code Playgroud) 为什么泛型被声明为方法的一部分?例如,在创建使用泛型的方法时,必须在方法修饰符之后包含泛型:
public static <T, K> void delete(AbstractDao<T, K> dao)
Run Code Online (Sandbox Code Playgroud)
方法的泛型部分未显示为方法声明的一部分.根据java文档,方法包含以下项目:
修改器 - 例如公共,私人和其他您将在稍后了解的内容.
返回类型 - 方法返回的值的数据类型,如果方法未返回值,则返回void.
方法名称 - 字段名称的规则也适用于方法名称,但约定略有不同.
括号中的参数列表 - 以逗号分隔的输入参数列表,前面是数据类型,括在括号中,().如果没有参数,则必须使用空括号.
参考:https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
我有一个项目,我正在尝试添加Android Auto支持.我已将以下代码添加到我的清单中,如Auto文档中所示:
<application
....
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
....
<service
android:name="com.me.auto.MyMediaBrowserService"
android:exported="false">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
....
</applicaiton>
Run Code Online (Sandbox Code Playgroud)
我也在使用我的gradle.build文件中定义的不同构建风格:
defaultConfig {
applicationId "com.me"
minSdkVersion 16
//noinspection OldTargetApi
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
productFlavors {
regular {
applicationId "com.me"
}
different {
applicationId "com.meother"
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用'常规'风格构建和安装时,android auto不起作用.但是,当我使用"不同"的味道构建和安装时,一切都很好.如果我然后将常规更改为applicaitonId'com.menew'之类的其他内容,那么Auto再次运行良好.
applicationId构建风格如何制作或破坏Android Auto功能?
当我尝试在 Google Play Console 中创建新应用程序时,它说我需要许可。我想知道我需要向业主请求什么许可。我查看了可用权限,它没有说明任何有关新应用程序的信息。
我有一个 SVG 字节数组,需要将其转换为 Android 中的图像。字节数组使用 Base64 进行编码。我相信 Android 不支持 SVG 图像,这导致我的转换方法返回 null。无论如何,这可以做到吗?
这是我尝试用来转换图像的方法:
public static Bitmap imageFromString(String imageData) {
String data = imageData.substring(imageData.indexOf(",") + 1);
byte[] imageAsBytes = Base64.decode(data.getBytes(), Base64.DEFAULT);
return BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
}
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚这个测试我做错了什么.这是我对该项目的第一次测试.
describe('Controller: landingCtrl', function () {
var scope;
beforeEach(angular.mock.module('myWebApp'));
beforeEach(angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.filters = {
date: 'This Week'
};
$controller('landingCtrl', {
$scope: scope
});
}));
it('dateFilter should return true', function () {
expect(true).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
这是输出:
Firefox 34.0.0 (Windows) Controller: landingCtrl dateFilter should return true FAILED
minErr/<@app/bower_components/angular/angular.js:63:12
loadModules/<@Capp/bower_components/angular/angular.js:4138:15
forEach@app/bower_components/angular/angular.js:323:11
loadModules@app/bower_components/angular/angular.js:4099:5
createInjector@app/bower_components/angular/angular.js:4025:11
workFn@app/bower_components/angular-mocks/angular-mocks.js:2425:44
Run Code Online (Sandbox Code Playgroud) android ×7
android-auto ×2
gradle ×2
testing ×2
angular-mock ×1
angularjs ×1
bitmap ×1
build.gradle ×1
crash ×1
generics ×1
groovy ×1
java ×1
macos ×1
methods ×1
stack-trace ×1
svg ×1
swift ×1