我很难搞清楚这一个.我无法在手机上重现(nexus 4).似乎没有影响所有设备,但我有足够的报告,看到它继续发生令人沮丧.
java.lang.ArrayIndexOutOfBoundsException: length=10; index=10
at android.text.StaticLayout.calculateEllipsis(StaticLayout.java:938)
at android.text.StaticLayout.out(StaticLayout.java:859)
at android.text.StaticLayout.generate(StaticLayout.java:524)
at android.text.StaticLayout.<init>(StaticLayout.java:147)
at android.widget.TextView.makeSingleLayout(TextView.java:6583)
at android.widget.TextView.makeNewLayout(TextView.java:6429)
at android.widget.TextView.onMeasure(TextView.java:6807)
at android.view.View.measure(View.java:16047)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1232)
at android.widget.TableRow.onMeasure(TableRow.java:114)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.TableLayout.measureVertical(TableLayout.java:476)
at android.widget.TableLayout.onMeasure(TableLayout.java:439)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16047)
at android.widget.ListView.measureScrapChild(ListView.java:1190)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1255)
at android.widget.ListView.onMeasure(ListView.java:1165)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16047)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at …Run Code Online (Sandbox Code Playgroud) 我通过以下方式插入图片:
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, filename);
values.put(Images.Media.DATE_ADDED, System.currentTimeMillis());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = this.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试删除时
File f = new File(imageURI);
f.delete();
Run Code Online (Sandbox Code Playgroud)
图片不再存在,但空占位符是.有任何想法吗?
我遇到一个奇怪的问题.我的应用程序可以写一个简单的文本文件到SD卡,有时它适用于一些人,但不适用于其他人,我不知道为什么.
对于某些人来说,如果他们...在文件中放置一些字符等强制关闭它.我似乎无法重现它,因为我没有麻烦,但这是处理文件写入的代码.任何人都可以想到可能导致问题的事情或更好的方法吗?
public void generateNoteOnSD(String sFileName, String sBody)
{
try
{
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists())
{
root.mkdirs();
}
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
}
catch(IOException e)
{
e.printStackTrace();
importError = e.getMessage();
iError();
}
}
Run Code Online (Sandbox Code Playgroud) 如果给定列包含内部任何位置的文本,则尝试创建将返回匹配的查询.例如,如果我要传递"真的"这个词,那么包含文本"这是一个非常长的文本行"的列将匹配.到目前为止,我的查询仅在完全匹配时返回,因此它只匹配包含"真实"的列,即它.
我尝试了几种方法,但两者似乎都返回了相同的结果:
第一种方式(s是我传入的字符串):
Cursor cursor = mDb.query(DATABASE_TABLE, new String[] {KEY_TITLE}, KEY_TITLE + " LIKE '%" + s + "%' COLLATE NOCASE", null, null, null, null);
Run Code Online (Sandbox Code Playgroud)
下一步
String p_query = "SELECT COUNT(*) FROM data WHERE number=? COLLATE NOCASE";
Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序,我希望能够通过用户输入(edittext)和十六进制值设置各种颜色,例如#eeeeee等.问题是我似乎无法弄清楚如何转换它们.
如果我在这样的代码中做一些事情就可以了:titlebar.setBackgroundColor(0xFF545455);
但是,如果我通过edittext检索一个值,说"545455"我无法让它工作
String tbColor = tb_color.getText().toString();
String value = "0xFF" + tbColor;
int setColor = Integer.valueOf(value);
titlebar.setBackgroundColor(setColor);
Run Code Online (Sandbox Code Playgroud)
任何人对如何实现这一点有任何想法?
我正在尝试创建我的应用程序数据库内容的备份,对于大多数设备来说,它工作正常,但有一些设备默认启用了 wal 模式,这会导致问题。从我读过的所有内容来看,调用“pragma wal_checkpoint”应该将 -wal 文件的内容刷新到主数据库文件中,这就是我所追求的。将内容刷新到主数据库文件,然后复制数据库文件进行备份。我正在打电话
db.rawQuery("pragma wal_checkpoint;", null);Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用。有任何想法吗?
使用图像滚动列表视图时.图像将消失,然后在一两秒后重新出现.任何有关此事的帮助将不胜感激!
这是在我的getView中调用以下代码:
image_main.setImageBitmap(null);
if (curr == 0 && image != null) {
list_image.setVisibility(View.VISIBLE);
image_preference = preferences.getString("image_preferences", "false");
time_right.setVisibility(View.GONE);
if (image_preference.equals("false")) {
ImageDownloader imgDwn = new ImageDownloader();
imgDwn.download(image, image_main, image_table);
}
Run Code Online (Sandbox Code Playgroud)
我的代码:
public class ImageDownloader {
public void download(String url, ImageView imageView, TableLayout imageTable) {
if (cancelPotentialDownload(url, imageView)) {
BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, imageTable);
DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
imageView.setImageDrawable(downloadedDrawable);
task.execute(url);
}
}
class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> {
String url;
private final WeakReference<ImageView> imageViewReference;
private final WeakReference<TableLayout> imageTableReference; …Run Code Online (Sandbox Code Playgroud) 我正在看看android SDK中的记事本示例,请看这里:http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html
事情是它只绘制光标所在的当前行,例如http://cdn2.staztic.com/screenshots/simple-notepad-app-al-1.jpg
但我想显示填满屏幕的线条,例如http://www.itismyworld.info/wp-content/uploads/2010/03/AK-notebook.png
任何建议都会很棒.相关的代码似乎在这里:
protected void onDraw(Canvas canvas) {
// Gets the number of lines of text in the View.
int count = getLineCount();
// Gets the global Rect and Paint objects
Rect r = mRect;
Paint paint = mPaint;
/*
* Draws one line in the rectangle for every line of text in the EditText
*/
for (int i = 0; i < count; i++) {
// Gets the baseline coordinates for the …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一定高度的缩略图,但保持纵横比.我正在使用下面的代码但问题出现时,如果图像有点小,生成的图像将不会填充缩略图区域.imageURI只是图像的路径.
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imageURI, o);
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=4;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale++;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
Bitmap bitmap = BitmapFactory.decodeFile(imageURI, o2);
Run Code Online (Sandbox Code Playgroud)