小编Nat*_*lie的帖子

Android Studio无法在导入org.junit.Before中解析符号'Before'

我在Android Studio项目中使用junit-4.12外部库包.出于某种原因,当我导入"import org.junit.Before;"时 进入我的java类我得到错误"无法解析符号'之前'"(这也发生在'测试'),即使我可以看到我的junit包中存在文件(见图).我也有我的gradle中列出的依赖项(见第2张图片).

我注意到有人问了一个类似的问题并且响应是"确保如果JUnit被声明为<scope> test </ scope>,那么你的测试类是在src/test中,否则它将无法看到依赖."

也许这是我的问题,但我不知道如何确保我的"测试类在src/test中".(我是android studio的新手...很抱歉,如果这是一个简单的问题)

"之前"和"测试"课程

Gradle依赖

java junit android unit-testing

5
推荐指数
2
解决办法
3868
查看次数

从字节数组转换为可绘制图像会导致图像损坏:Android

我正在将图像转换为字节数组。通过套接字发送它,然后一旦它通过套接字,我需要将它转换回可绘制、png 或任何类型的图像,我可以将其用作图像按钮的背景。问题是,当我转换为字节数组或从数组转换为可绘制对象时,文件已损坏。

我从手机上最后安装的应用程序中获取原始图像,如下所示,然后将其保存到手机上的文件中,以便我可以检查此时图像文件是否已成功捕获(确实如此。没有任何损坏这一点):

final PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(intent.getData().getSchemeSpecificPart(), 0);
Drawable icon = context.getPackageManager().getApplicationIcon(ai);
BitmapDrawable bitmapIcon = (BitmapDrawable)icon;

FileOutputStream fosIcon = context.openFileOutput(applicationName + ".png", Context.MODE_PRIVATE);

bitmapIcon.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, fosIcon);
InputStream inputStream = context.openFileInput(applicationName + ".png");

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);


// GET FILE DIRECTORY

File imageFile = new File(context.getFilesDir(), applicationName + ".png");
Run Code Online (Sandbox Code Playgroud)

现在我将此位图转换为字节数组以通过套接字发送:

// get bitmap image in bytes to send

        int bytes = bitmap.getByteCount();
        Log.d("tag_name", "Number of Bytes" + bytes);

        ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new …
Run Code Online (Sandbox Code Playgroud)

java sockets arrays android image

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

标签 统计

android ×2

java ×2

arrays ×1

image ×1

junit ×1

sockets ×1

unit-testing ×1