小编The*_*ian的帖子

Robolectric是否需要Java 9?

所有测试都通过了,但是我得到以下警告。Robolectric告诉我需要Java 9。我正在使用最新版本的Robolectric。

[Robolectric] WARN: Android SDK 10000 requires Java 9 (have Java 8). Tests won't be run on SDK 10000 unless explicitly requested.
[Robolectric] com.example.testcaseWithRobolectric.MainActivityTest.testAllElements: sdk=28; resources=BINARY
Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28
Run Code Online (Sandbox Code Playgroud)

流程结束,退出代码为0

这是我的摇篮:

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation project(path: ':domain_layer')
        testImplementation "org.robolectric:robolectric:4.3"
    }

defaultConfig {
        applicationId "com.example.testcaseWithRobolectric"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
Run Code Online (Sandbox Code Playgroud)

android unit-testing robolectric

16
推荐指数
4
解决办法
4851
查看次数

Android 应用程序在 Windows 资源管理器中不可见,警告 ls: /storage/emulated/: 权限被拒绝

重新安装项目后,我的包在 android studio 设备资源管理器的 sdCard 文件夹中不可见。在卸载之前,这不是问题,我从未对清单中的权限或运行时权限请求进行任何更改。当我使用 Windows 资源管理器并导航到 /android/data 文件夹时,我的包不存在。但我的应用程序在设备中正常运行。我用的是android studio 4.0

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="com.example.package.MyService"
            android:exported="true"/>
Run Code Online (Sandbox Code Playgroud)

我可以看到我的设备已授予存储权限。

在此输入图像描述

android android-permissions android-studio

14
推荐指数
2
解决办法
8931
查看次数

Android Navigation Instrumentation 测试抛出方法 addObserver 必须在主线程上调用

我有两个 Fragment,一个是我图中的 home 片段。单击按钮后,用户将被导航到第二个片段。它通过将用户导航到第二个片段并显示文本来按预期工作。所以图很好。

现在我想编写一个仪器测试。

@RunWith(AndroidJUnit4::class)
class TransitionTest {

    @Test
    fun testNavigationToSecondFragment() {
        
        val navController = TestNavHostController(
            ApplicationProvider.getApplicationContext())

        navController.setGraph(R.navigation.my_graph) <--throws exception

        // the rest of my test continues here
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,上面显示的用于设置图形的行会引发以下异常:

IllegalStateException:必须在主线程上调用方法 addObserver。

我的环境:

fragment_version = 1.2.5 nav_version = 2.3.1 浓缩咖啡 = 3.3.0

有谁知道发生了什么以及如何解决它?

kotlin android-espresso android-navigation-graph

12
推荐指数
2
解决办法
5312
查看次数

android在不同的设备中通信两个应用程序

这里的所有问题都指向相同应用程序的类或不同的应用程序在同一设备中的不同进程中.我想在两个独立的设备中向两个独立的应用程序发送数据.我尝试使用broadcastreceiver但它没有用.这是我发送数据的代码段.

addressstring = String.valueOf(acrilocation.getText());
            if (addressstring != null && addressstring.length() > 0){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Constants.LOCATION_DATA_EXTRA, addressstring);
            intent.setType("text/plain");
            sendBroadcast(intent);
            } else{
                Toast.makeText(getApplicationContext(), "Enter valid location address", Toast.LENGTH_SHORT).show();
            }
Run Code Online (Sandbox Code Playgroud)

但是当我使用以下代码片段在我的其他应用程序中收到数据时,它会失败.当我调试应用程序时,我得到null异常.

Intent intent = getIntent();
        String action = intent.getAction();
        String data = intent.getStringExtra(Intent.EXTRA_INTENT);
        String type = intent.getType();
        useraddress.setText(data);
           startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

还有另一种方法来实现这一目标吗?我的意思是发送数据到另一个设备中安装的另一个应用程序?

android communication

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

Android Studio更新后的Java.lang.ClassNotFoundException

我从稳定的频道更新到Android Studio 2.1.我一做到这一点,我就得到了我的登录类的ClassNotFoundException,它在清单中声明了很长时间.在更新之前,我的应用程序编译正常.

com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp, PID: 29605
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.myapp/com.myapp.Login}: java.lang.ClassNotFoundException: Didn't find class "com.myapp.Login" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3023)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3294)
    at android.app.ActivityThread.access$1000(ActivityThread.java:210)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1704)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.Login" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1094)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3013)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3294) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:210) 
    at …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-studio-2.1

8
推荐指数
2
解决办法
2万
查看次数

如何在windows中向android studio添加配置文件?

Google已经更改了用于生成注册ID和GCM的文档.与往常一样,文档是不完整的,包括非功能代码,其中之一是将配置文件添加到项目中.我被困在这一步.

$ move path-to-download/google-services.json app/ is invalid windows command. Can someone correct this syntax for me please?
Run Code Online (Sandbox Code Playgroud)

android configuration-files android-studio

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

Android Wear模块中的“意外的名称空间前缀“ app””

我根据此Google文档添加了一个新的Android Wear模块

但出现标题中描述的错误。这是我的布局。

<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/dark_grey"
    android:padding="@dimen/box_inset_layout_padding"
    tools:context=".MainWearActivity"
    tools:deviceIds="wear">  

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/inner_frame_layout_padding"
        app:boxedEdges="all">  <---this is the offending line 

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />

    </FrameLayout>
</android.support.wear.widget.BoxInsetLayout>
Run Code Online (Sandbox Code Playgroud)

有人知道发生了什么吗?感谢您对我为什么收到此错误的解释。更新:我删除了多余的android前缀。Android Studio要求我更改应用程序前缀以更改为android,但即使这样做,错误仍然存​​在。现在是安全的时间来假设它是一个错误吗?

android android-wear-data-api android-wear-complication

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

如何在Kotlin中设置属性值

我试图设置一个属性值,如下面的代码片段所示.这个问题并没有回答这个问题.

var person = Person("john", 24)
        //sample_text.text = person.getName() + person.getAge()
        var kon = person.someProperty
        person.someProperty = "crap" //this doesn't allow me to set value
        kon = "manulilated"  //this allows me to set the value
        sample_text.text = kon

class Person(val n: String, val a: Int){
    var pname: String = n
    var page: Int = a

    var someProperty: String = "defaultValue"
        get() = field.capitalize()
        private set(value){field = value}
    fun Init(nm: String, ag: Int){
        pname = nm
        page = ag …
Run Code Online (Sandbox Code Playgroud)

android kotlin

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

ResultReceiver.send抛出nullpointerexception

我找了一个答案,但找不到答案.我在IntentService中反向地理编码纬度和纬度,然后当我尝试ResultReceiver.send时它会抛出nullpointerexception.我调试了参数,它们包含地址和结果代码,就像它们应该的那样.我搜索了任何未初始化的对象,但我不能很好.谁能给我一些关于发生了什么的线索?

这是对lat和lon进行反编码的方法.

@Override
    public void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        String errorMessage = "";

        // Get the location passed to this service through an extra.
        Location location = intent.getParcelableExtra(
                Constants.LOCATION_DATA_EXTRA);

        List<Address> addresses = null;

        try {
            addresses = geocoder.getFromLocation(
                    location.getLatitude(),
                    location.getLongitude(),
                    // In this sample, get just one addresse.
                    1);
        } catch (IOException ioException) {
            // Catch network or other I/O problems.
            errorMessage = getString(R.string.service_not_available);
            Log.e(TAG, errorMessage, ioException);
        } catch (IllegalArgumentException …
Run Code Online (Sandbox Code Playgroud)

java android nullpointerexception intentservice

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