下面的代码在Kotlin/Android中崩溃,底部提供了堆栈跟踪。它是从Java/Android转换而来的,后者没有这样的问题。还提供了原始Java代码。当我试图向密码字段添加字符时,会发生崩溃。编辑现有的字符工作得很好。
我有两个问题:
mPwd!!.transformationMethod = object : PasswordTransformationMethod() {
override fun getTransformation(source: CharSequence, view: View): CharSequence {
return PasswordCharSequence(source)
}
internal inner class PasswordCharSequence(private val source: CharSequence)// Store char sequence
: CharSequence {
val mSource = source
public override val length = mSource.length
init {
App.d(TAG, "SOURCE " + mSource + " " + length)
}
override fun get(index: Int): Char {
App.d(TAG, "SOURCE IND " + index + " " + mSource.length)
return if (mChkUnmask!!.isChecked) mSource.get(index) else '*'
}
override fun subSequence(start: Int, end: Int): CharSequence {
App.d(TAG, "SOURCE SUB " + start + " " + end)
return mSource.subSequence(start, end) // Return default
}
}
}
mPwd.setTransformationMethod(new PasswordTransformationMethod() {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
return mChkUnmask.isChecked()?mSource.charAt(index):'*';
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
});
06-03 00:35:08.143 16694 16694 E AndroidRuntime: java.lang.IndexOutOfBoundsException
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.graphics.Paint.getRunAdvance(Paint.java:2986)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.TextLine.handleText(TextLine.java:719)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.TextLine.handleRun(TextLine.java:873)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.TextLine.measureRun(TextLine.java:387)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.TextLine.measure(TextLine.java:277)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.TextLine.metrics(TextLine.java:251)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.Layout.getLineExtent(Layout.java:1072)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.text.Layout.getLineWidth(Layout.java:1038)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.TextView.desired(TextView.java:8142)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.TextView.onMeasure(TextView.java:8208)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.view.View.measure(View.java:21051)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.view.View.measure(View.java:21051)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.view.View.measure(View.java:21051)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.view.View.measure(View.java:21051)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459)
06-03 00:35:08.143 16694 16694 E AndroidRuntime: at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:400)
10是这里的CharSequence长度。第一个数字-当前索引。当我试图从键盘添加索引为9的字符时,会发生崩溃。它从未被添加,也没有显示在下面的输出中
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 810
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 710
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 610
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 510
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 410
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 310
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 210
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 110
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 010
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 010
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 110
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 210
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 310
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 410
06-03 00:35:08.121 16694 16694 D GAC-STORE: SOURCE IND 510
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 610
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 710
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 810
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 010
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 110
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 210
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 310
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 410
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 510
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 610
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 710
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 810
06-03 00:35:08.122 16694 16694 D GAC-STORE: SOURCE IND 810
mPwd布局
<EditText
android:id="@+id/txtDlgPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/chkStorePwd"
android:hint ="Ecnryption Password"
android:maxLines="1"
android:singleLine="true"
android:inputType="textPassword|textNoSuggestions"
android:imeOptions="actionDone"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:textSize="15sp"/>
幸运的是,Android/Kotlin允许在单个项目中混合Java和Kotlin文件。我用这个来解决这个问题。
创建了一个用于密码处理的Java类。请注意,CharSequence在这里是一个原生Java类,这是不同的。
import java.lang.CharSequence;
public class PasswordHandler implements CharSequence {
private CharSequence mSource;
private Switch mUnmask;
public PasswordHandler(CharSequence source, Switch unmask) {
mSource = source;
mUnmask = unmask;
}
public char charAt(int index) {
return mUnmask.isChecked()?mSource.charAt(index):'*';
}
public int length() {
return mSource.length();
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end);
}
@NonNull
@Override
public String toString() {
String star = new String();
int l = length();
if (!mUnmask.isChecked()) {
while (l-- > 0){
star += "*";
}
}
return mUnmask.isChecked()? mSource.toString():star;
}
}
在Kotlin类的getTransfromation方法中实例化了该类。Kotlin编译器这次把握得很好。崩溃不会再发生了。我仍然希望看到一个纯粹的科特林解决方案。
mPwd!!.transformationMethod = object : PasswordTransformationMethod() {
override fun getTransformation(source: CharSequence, view: View): CharSequence {
return PasswordHandler(source, mChkUnmask)
}
}
我是Android开发的新手。我能够使这个应用程序在Android5.1中工作,但是,当我试图在Android4.1中部署这个应用程序时,它在主活动本身就会崩溃。我理解它,因为我使用的是矢量图像和Android4.1不兼容它。为了克服这一点,我设置了如下所述的代码: 我现在收到这个错误 代码文件 XML文件 请帮助我调试这个。我有点被困住了,需要你的帮助。
这里是我的主要活动 } 我感觉runOnUiThread方法有问题。感谢你的帮助.
我碰壁了,没有帮助我过不去。 我正在尝试使用Java Servlet为我的Android应用程序进行简单的登录和注册,问题是当我在Tomcat/Eclipse上本地运行它时,一切都正常,但当我在Heroku free服务器上部署WAR文件时,数据库部分似乎根本不起作用。 我怀疑这实际上是驱动程序的问题,但我无法获取日志,因为我通过我的Android应用程序连接到它。 我在freesqldataba
我有应用程序上传在玩商店。它在调试模式下运行良好,但当我从play store下载相同的APK(发布模式)时,它就崩溃了。我无法确定堆栈跟踪没有给出准确的错误位置。 java.lang.RuntimeException:在Android.os.AsyncTask$3上完成(asynctask.java:318)在java.util.concurrent.FutureTask.FinishCompl
Build.Gradle(模块:应用程序) Logcat(错误):
我们刚刚从Visual Studio2008“升级”到Visual Studio2012。我们更新了我们的单元测试,现在它们在单独运行时通过,但是当我尝试运行全部时,我得到了以下错误: 还有人遇到过类似的问题吗?如果是的话,你是怎么解决的? 在MSDN上也问过同样的问题,但答案是“点击崩溃转储的链接”。这个答案对我没有帮助,因为我没有看到到崩溃转储的任何链接,并且我无法生成崩溃转储。 关于Stac