- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在尝试从我的 sqlite 数据库中检索 blob 并将其设置为 ImageView 中的位图时遇到问题, ImageView 是我的 ListView 使用的布局。数据库中的文本很好,但是当我尝试将 ImageView 设置为已从数据库中读入的位图时出现错误。这是代码:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.*;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.*;
import android.widget.TabHost.TabSpec;
public class StudentTrackerActivity extends Activity implements OnClickListener {
final static int cameraData = 0;
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private static final int REQUEST_CODE = 192837;
private static final String BUFF_INFO = null;
public byte[] imgByte = null;
public final Bitmap imgBitmap = null;
public ImageView imgPic;
public ImageButton imgCamera;
public ImageView imgSpeaker;
public ImageView imgIcon;
public Bitmap bm;
public Intent i;
public ByteArrayOutputStream out = new ByteArrayOutputStream(128);
InputStream is;
StringBuffer sb;
Button btnAddStudentRecord;
boolean bRecordAdded = true;
public ListView list;
public EditText txtStudentName;
public EditText txtDOB;
public EditText txtAddress1;
public EditText txtAddress2;
public EditText txtTown;
public EditText txtPostcode;
public EditText txtPhone;
public TextView txtFname;
public TextView txtDateOfBirth;
public String strStudentName;
public String strDOB;
public String strAddress1;
public String strAddress2;
public String strTown;
public String strPostcode;
public String strPhone;
public String strMatches;
public List<String> results = new ArrayList<String>();
@SuppressWarnings({ "unchecked", "rawtypes" })
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
sb = new StringBuffer();
imgCamera = (ImageButton) findViewById(R.id.imgCamera);
imgPic = (ImageView) findViewById(R.id.imgPic);
imgSpeaker = (ImageView) findViewById(R.id.imgSpeaker);
imgIcon = (ImageView) findViewById(R.id.icon);
btnAddStudentRecord = (Button) findViewById(R.id.btnAddStudentRecord);
txtStudentName = (EditText) findViewById(R.id.txtStudentName);
txtDOB = (EditText) findViewById(R.id.txtDOB);
txtAddress1 = (EditText) findViewById(R.id.txtAddress1);
txtAddress2 = (EditText) findViewById(R.id.txtAddress2);
txtTown = (EditText) findViewById(R.id.txtTown);
txtPostcode = (EditText) findViewById(R.id.txtPostcode);
txtPhone = (EditText) findViewById(R.id.txtPhone);
txtFname = (TextView) findViewById(R.id.txtFname);
// txtDateOfBirth = (TextView) findViewById(R.id.txtDateOfBirth);
list = (ListView) findViewById(R.id.list);
//convert edit text values to string values
strStudentName = txtStudentName.getText().toString();
strDOB = txtDOB.getText().toString();
strAddress1 = txtAddress1.getText().toString();
strAddress2 = txtAddress2.getText().toString();
strTown= txtTown.getText().toString();
strPostcode = txtPostcode.getText().toString();
strPhone = txtPhone.getText().toString();
TabHost th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("", getResources().getDrawable(R.drawable.student));
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("", getResources().getDrawable(R.drawable.camera));
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("Tab3");
th.addTab(specs);
specs = th.newTabSpec("tag4");
specs.setContent(R.id.tab4);
specs.setIndicator("Search", getResources().getDrawable(R.drawable.magnify));
th.addTab(specs);
//set listener for speaker button
imgSpeaker.setOnClickListener(new SpeakerButtonHandler());
//set listener for camera button
imgCamera.setOnClickListener(this);
//set listener for add student button
btnAddStudentRecord.setOnClickListener(new AddStuButtonHandler());
//make silhouette default image
is = getResources().openRawResource(R.drawable.silhouette);
bm = BitmapFactory.decodeStream(is);
//display students in listview
DisplayaAllStudents();
}
public void onClick(View v) {
int vNum = v.getId();
switch(vNum){
case R.id.imgCamera:
//capture photo of student
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
}
}
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
public void flushBuffer(){
sb.delete(0, sb.length());
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try{
if(resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bm = (Bitmap)extras.get("data");
imgPic.setImageBitmap(bm);
}
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
//add text to string buffer and display
//it on notepad
//flush string buffer of previous content
flushBuffer();
//remove square brackets
strMatches = matches.toString().replace("[","").replace("]", "");
//add string to string buffer
sb.append(strMatches.toString() + "\n");
//check which edit text field has the
//focus then populate the field with the
//contents of the voice recognition string
if(txtStudentName.isFocused()){
txtStudentName.setText(sb.toString());
}
else if(txtDOB.isFocused()){
txtDOB.setText(sb.toString());
}
else if(txtAddress1.isFocused()){
txtAddress1.setText(sb.toString());
}
else if(txtAddress2.isFocused()){
txtAddress2.setText(sb.toString());
}
else if(txtTown.isFocused()){
txtTown.setText(sb.toString());
}
else if(txtPostcode.isFocused()){
txtPostcode.setText(sb.toString());
}
else if(txtPhone.isFocused()){
txtPhone.setText(sb.toString());
}
}
}catch(Exception ex){
ex.printStackTrace();
}
}
private class AddStuButtonHandler implements OnClickListener{
public void onClick(View v) {
if(v.getId() == R.id.btnAddStudentRecord){
addRecord();
//DisplayaAllStudents();
//Toast.makeText(getApplicationContext(), "Testing!!!", Toast.LENGTH_SHORT).show();
}
}
}
public void addRecord(){
DBAdapter db = new DBAdapter(this);
db.open();
long id;
//prepare and compress bitmap for database insert
bm.compress(CompressFormat.PNG, 100, out);
id = db.insertStudent(txtStudentName.getText().toString(),
txtDOB.getText().toString(),
txtAddress1.getText().toString(),
txtAddress2.getText().toString(),
txtTown.getText().toString(),
txtPostcode.getText().toString(),
txtPhone.getText().toString(),
out.toByteArray()
);
if(bRecordAdded){
Toast.makeText(getApplicationContext(), "Record successfully added", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "Error: could not add record", Toast.LENGTH_SHORT).show();
}
db.close();
}
@SuppressWarnings("unchecked")
public void DisplayaAllStudents(){
DBAdapter db = new DBAdapter(this);
db.open();
Cursor c = db.getAllStudents();
if(c.moveToFirst()){
do{
String stuName = c.getString(c.getColumnIndex(db.KEY_STUDENTNAME));
String stuDOB = c.getString(c.getColumnIndex(db.KEY_DOB));
results.add(" " + stuName.toString() + ", D.O.B: " + stuDOB);
//read image from database and insert into image view
imgByte = c.getBlob(8);
ByteArrayInputStream is = new ByteArrayInputStream(imgByte);
Bitmap picBitmap = BitmapFactory.decodeStream(is);
imgIcon.setImageBitmap(picBitmap);
//display record
//DisplayStudent(c);
}while(c.moveToNext());
}
//bind data to list view
list.setAdapter(new ArrayAdapter<String>(StudentTrackerActivity.this,R.layout.datalayout,R.id.txtFname,results));
db.close();
}
public void DisplayStudent(Cursor c){
Toast.makeText(getApplicationContext(),
"StudentName: " + c.getString(1) + "\n" +
"D.O.B:" + c.getString(2) + "\n" +
"Address1: " + c.getString(3) + "\n" +
"Address2: " + c.getString(4) + "\n" +
"Town: " + c.getString(5) + "\n" +
"Postcode: " + c.getString(6) + "\n" +
"Phone: " + c.getString(7) + "\n" +
"Pic: " + c.getBlob(8)
,
Toast.LENGTH_LONG).show();
}
private class SpeakerButtonHandler implements OnClickListener{
public void onClick(View v) {
if(v.getId() == R.id.imgSpeaker){
startVoiceRecognitionActivity();
}
}
}
}
11-17 13:22:58.506: INFO/System.out(25430): waiting for debugger to settle...
11-17 13:22:58.707: INFO/System.out(25430): waiting for debugger to settle...
11-17 13:22:58.907: INFO/System.out(25430): waiting for debugger to settle...
11-17 13:22:59.109: INFO/System.out(25430): debugger has settled (1463)
11-17 13:22:59.307: ERROR/gralloc(126): [unregister] handle 0x393b98 still locked (state=40000001)
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): updateAllElements
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): updateTime
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): setCalendarInstance
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): onTimeChanged
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): mHour01HandIndex = 1
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): mHour01HandIndex = 3
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): mHour01HandIndex = 2
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): mHour01HandIndex = 3
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): updateTime id = 3
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): updateCurrentTemperature
11-17 13:23:00.127: INFO/WeatherClockWidgetProvider(5101): changeFtoC
11-17 13:23:00.137: INFO/WeatherClockWidgetProvider(5101): updateCurrentLocal
11-17 13:23:00.147: INFO/WeatherClockWidgetProvider(5101): updateTemperatures
11-17 13:23:00.147: INFO/WeatherClockWidgetProvider(5101): setCalendarInstance
11-17 13:23:00.177: INFO/WeatherClockWidgetProvider(5101): highT = 60
11-17 13:23:00.177: INFO/WeatherClockWidgetProvider(5101): lowT = 47
11-17 13:23:00.177: INFO/WeatherClockWidgetProvider(5101): changeFtoC
11-17 13:23:00.197: INFO/WeatherClockWidgetProvider(5101): changeFtoC
11-17 13:23:00.197: INFO/WeatherClockWidgetProvider(5101): updateDate
11-17 13:23:00.197: INFO/WeatherClockWidgetProvider(5101): setCalendarInstance
11-17 13:23:00.207: INFO/WeatherClockWidgetProvider(5101): updateWeatherDescription
11-17 13:23:00.207: INFO/WeatherClockWidgetProvider(5101): updateUpdatedTime
11-17 13:23:00.207: INFO/WeatherClockWidgetProvider(5101): setCalendarInstance
11-17 13:23:00.207: ERROR/updateUpdatedTime dateString(5101): 11/13/2011
11-17 13:23:00.237: ERROR/updatedTime before(5101): Update: NOV.13 4:14 PM
11-17 13:23:00.237: ERROR/updatedTime end(5101): Update: NOV.13 4:14 PM
11-17 13:23:00.297: INFO/WeatherClockWidgetProvider(5101): bindViews
11-17 13:23:00.297: INFO/WeatherClockWidgetProvider(5101): appWidgetId = 3
11-17 13:23:03.157: WARN/wpa_supplicant(189): Failed to initiate AP scan.
11-17 13:23:05.517: WARN/ActivityManager(126): Launch timeout has expired, giving up wake lock!
11-17 13:23:05.777: WARN/ActivityManager(126): Activity idle timeout for HistoryRecord{447ec880 com.StudentTracker/.StudentTrackerActivity}
11-17 13:23:07.467: WARN/GDataClient(126): Unable to execute HTTP request.java.net.UnknownHostException: Host is unresolved: android.clients.google.com:443
11-17 13:23:09.161: WARN/wpa_supplicant(189): Failed to initiate AP scan.
11-17 13:23:15.162: WARN/wpa_supplicant(189): Failed to initiate AP scan.
堆栈跟踪:
StudentTracker_Debug [Android Application]
DalvikVM[localhost:8603]
Thread [<3> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2496
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2512
ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 119
ActivityThread$H.handleMessage(Message) line: 1863
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4363
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
最佳答案
不要将图像放入数据库中。一般来说,它只是一种糟糕的形式,会让你的数据库查询变得非常慢。相反,将文件路径存储到数据库中的图像并根据需要加载图像。请看这个link以获得更详细的答案。
关于android - 检索 sqlite blob 字段以放入 imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8169308/
在有些场景下,我们需要对我们的varchar类型的字段做修改,而修改的结果为两个字段的拼接或者一个字段+字符串的拼接。 如下所示,我们希望将xx_role表中的name修改为name+id。
SELECT incMonth as Month, SUM( IF(item_type IN('typ1', 'typ2') AND incMonth = Month, 1, 0 ) )AS
我最近读到 volatile 字段是线程安全的,因为 When we use volatile keyword with a variable, all the threads read its va
我在一些模型中添加了一个 UUID 字段,然后使用 South 进行了迁移。我创建的任何新对象都正确填充了 UUID 字段。但是,我所有旧数据的 UUID 字段为空。 有没有办法为现有数据填充 UUI
刚刚将我的网站从 mysql_ 更新为 mysqli,并破坏了之前正常运行的查询。 我试图从旋转中提取 id,因为它每次都会增加 1,但我不断获取玩家 id,有人可以告诉我我做错了什么吗?我尝试了将
我在 Mac OS X 上使用带有 Sequel Pro 的 MySQL。我想将一个表中的一个字段(即名为“GAME_DY”的列)复制到另一个名为“DAY_ID”的表的空字段中。两个表都是同一数据库的
问题: 是否有可能有一个字段被 JPA 保留但被序列化跳过? 可以实现相反的效果(JPA 跳过字段而序列化则不会),如果使用此功能,那么相反的操作肯定会很有用。 类似这样的事情: @Entity cl
假设我有一个名为“dp”的表 Year | Month | Payment| Payer_ID | Payment_Recipient | 2008/2009 | July
我将尝试通过我的 Raspberry Pi 接入点保证一些 QoS。 开始之前,我先动手:我阅读了有关 tcp、udp 和 ip header 的内容。在IP header description我看
如果你能弄清楚如何重命名这个问题,我愿意接受建议。 在 Dart 语言中,可以编写一个带有 final 字段的类。这些是只能设置的字段构造函数前 body 跑。这可以在声明中(通常用于类中的静态常量)
你怎么样? 我有两个带有两个字段的日期选择器 我希望当用户选择 (From) 时,第二个字段 (TO) 将是 next day 。比如 booking.com 例如:当用户选择From 01-01-2
我想我已经看到了这个问题的一些答案,这些答案可能与我需要的相差不远,但我对 mysql 的了解还不够确定,所以我会根据我的具体情况提出问题。 我有一个包含多个表的数据库,为此,如果“image”表上的
我在 mySQL 数据库中有 2 个表: customers ============ customer_id (1, 2 ) customer_name (john, mark) orders ==
我正在开发一个员工目标 Web 应用程序。 领导/经理在与团队成员讨论后为他们设定目标。这是一年/半年/季度,具体取决于组织遵循的评估周期。 现在的问题是添加基于时间段的字段或存档上一季度/年度数据的
我正在寻找允许内容编辑器从媒体库中选择多个文件的东西,这些文件将在渲染中列出。他们还需要能够上传文件和搜索。它必须在页面编辑器(版本 8 中称为体验编辑器)中工作。 到目前为止我所考虑的: 一堆文件字
现在,我有以下由 original.df %.% group_by(Category) %.% tally() %.% arrange(desc(n)) 创建的 data.frame。 DF 5),
我想知道是否有一些步骤/解决方案可以处理错误消息并将它们放入 Pentaho 工具中的某个字符串或字段中?例如,如果连接到数据库时发生某些错误,则将该消息从登录到字符串/字段。 最佳答案 我们在作业的
如何制作像短信应用程序一样的“收件人”字段?例如,右侧有一个“+”按钮,当添加某人时,名称将突出显示并可单击,如圆角矩形等。有没有内置的框架? 最佳答案 不,但请参阅 Three20 的 TTMess
是否可以获取记录的元素或字段的列表 通过类型信息类似于类的已发布属性的列表吗? 谢谢 ! 最佳答案 取决于您的delphi版本,如果您使用的是delphi 2010或更高版本,则可以使用“新rtti”
我正在构建一个 SQLite 数据库来保存我的房地产经纪人的列表。我已经能够使用外键来识别每个代理的列表,但我想在每个代理的记录中创建一个列表;从代理商和列表之间的一对一关系转变为一对多关系。 看这里
我是一名优秀的程序员,十分优秀!