所以我有一些有 2000~3000 行代码的大文件。使用模拟器调试时,我设置了断点并想检查一些变量,完成“收集数据”需要 1 分钟。与将光标移动到执行“评估”的变量相同。我不知道这是否与 Kotlin 有关系。在 Java 中似乎没有这个问题,即使它是大文件(不记得了)。
我的电脑很强大,所以应该不会导致这个问题。同时将 Android Studio 和 Kotlin 升级到最新版本。
有没有大文件也有同样的问题?调试变得非常困难......非常痛苦......
我有两个谷歌帐户。一个是我个人使用,另一个是我的应用程序。如果我同时登录并打开 AdMob 控制台,它始终显示我的个人帐户一。我找不到切换到另一个帐户的方法。在一些 Google 应用程序(例如 Gmail)中,我可以通过单击右上角的个人资料图片来完成此操作。但在 AdMob 中,我不能。唯一的解决办法就是我必须注销我的个人帐户,这很烦人。有没有办法在不注销另一个帐户的情况下切换帐户?
例如,如果我有这些代码:
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
mUser.setName("Roy");
realm.commitTransaction();
textView1.setText(mUser.getName());
Run Code Online (Sandbox Code Playgroud)
根据该文档,它表示Exception如果事务中存在错误,将捕获并且数据将不会保留.所以在上面的代码中,如果出现错误mUser.setName("Roy");或者说realm.commitTransaction();,不会出现崩溃,代码仍会继续?但是,cancelTransaction在这种情况下不会调用.会发生什么?更新:看起来应用程序不会崩溃,但下次如果你继续从Realm读取内容它会崩溃并告诉你Realm被锁定,因为没有调用commitTransaction.
我只是不知道你将使用什么机会,beginTransaction以及commitTransaction是否存在可能发生错误的风险.有好处executeTransaction,executeTransactionAsync可以很好地处理它.特别是executeTransactionAsync,我想你们中的大多数会使用executeTransactionAsync,因为它有onSuccess和onError.
对我来说,我只能想到一个原因:我想做一个简单的数据更新,仍然使用相同的线程.在这种情况下,我将使用:
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
mUser.setName("Roy");
}
});
} catch (Exception e) {
Logger.e(TAG, "error", e);
Toast.makeText(getActivity(), R.string.error_occurred, Toast.LENGTH_SHORT).show();
return;
}
Run Code Online (Sandbox Code Playgroud) 我希望TextView文本太长时能够扭曲其文本。
我正在使用链方法进行布局。但是没有得到我想要的。
看起来是这样的:
这是我要实现的目标:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_gravity="center_vertical"
android:background="@drawable/bg_trans_bg_light_top_bdr"
android:orientation="horizontal"
tools:showIn="@layout/fragm_edit_split">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/iv_user_photo"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="16dp"
android:src="@drawable/homer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
app:layout_constraintVertical_weight="1"
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="This is a very long long long long name"
android:textColor="#000"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/iv_user_photo"
app:layout_constraintEnd_toStartOf="@+id/v_space"
app:layout_constraintStart_toEndOf="@+id/iv_user_photo"
app:layout_constraintTop_toTopOf="@+id/iv_user_photo" />
<android.support.v4.widget.Space
android:id="@+id/v_space"
android:layout_width="0dp"
android:layout_height="1dp"
app:layout_constraintEnd_toStartOf="@+id/tv_dollar_sign"
app:layout_constraintStart_toEndOf="@+id/tv_name" />
<TextView
android:id="@+id/tv_dollar_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$"
android:textColor="@color/text_light"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/et_amount"
app:layout_constraintEnd_toStartOf="@+id/et_amount"
app:layout_constraintStart_toEndOf="@id/v_space"
app:layout_constraintTop_toTopOf="@+id/et_amount" />
<EditText
android:id="@+id/et_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:background="@null"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:inputType="number" …Run Code Online (Sandbox Code Playgroud) 我正在测试的类中有两个私有字段,这两个字段在构造函数中初始化。
现在,当我尝试使用用 @InjectMocks 注释的类进行调用时,它会抛出异常:
Cannot instantiate @InjectMocks field named 'ServiceImpl' of type 'class com.test.ServiceImpl'. You haven't provided the instance at field declaration so I tried to construct the instance.
Run Code Online (Sandbox Code Playgroud)
下面是一段代码。
public class ServiceImpl implements Service {
private OfficeDAO officeDAO;
private DBDAO dbDAO;
public ServiceImpl() {
officeDAO = Client.getDaoFactory().getOfficeDAO();
dbDAO = Client.getDaoFactory().getDBDAO();
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试课:
@RunWith(MockitoJUnitRunner.class)
public class ServiceImplTest {
@Mock
private OfficeDAO officeDAO;
@Mock
private DBDAO dbDAO;
@Mock
Client client;
@InjectMocks
private ServiceImpl serviceImpl;
@Mock
private Logger log;
@Before
public …Run Code Online (Sandbox Code Playgroud) 在Kotlin我有一个数据类.
data class APIResponse<out T>(val status: String, val code: Int, val message: String, val data: T?)
Run Code Online (Sandbox Code Playgroud)
我想声明另一个类来包含这个:
class APIError(message: String, response: APIResponse) : Exception(message) {}
Run Code Online (Sandbox Code Playgroud)
但是Kotlin给出错误:com.mypackagename中定义的类APIResponse需要一个类型参数
在Java中我可以这样做:
class APIError extends Exception {
APIResponse response;
public APIError(String message, APIResponse response) {
super(message);
this.response = response;
}
}
Run Code Online (Sandbox Code Playgroud)
如何将代码转换为Kotlin?
我有一个 v-data-table,并且可以对标题进行排序。然而,我发现在小屏幕中,所有标题都被 Vuetify 变成了下拉列表。我不想要这个功能,有没有可以禁用的选项?我想把我所有的标题都带回来..
android ×3
java ×2
kotlin ×2
admob ×1
junit ×1
mocking ×1
realm ×1
svn ×1
v-data-table ×1
vuetify.js ×1