public class uglyDetailActivity extends Activity {
public static final String TAG = "uglyDetailActivity";
TextView txtMsg;
ImageView ImageView1;
private String[] imgPath;
private String imagePath;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail2);
txtMsg = (TextView)findViewById(R.id.txtMsg);
ImageView1 = (ImageView)findViewById(R.id.ImageView1);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String NAME = bundle.getString("data0");
String UGLYCODE = bundle.getString("data1");
String JOB = bundle.getString("data2");
String NEXT = bundle.getString("data3");
Cursor cursor = uglyDatabaseHelper.queryUGLYDETAILSTable(UGLYCODE);
HandleCursorData (cursor );
}
public void HandleCursorData ( Cursor outCursor ) {
int recordCount = outCursor.getCount();
println("cursor count : " + recordCount + "\n");
int UGLYCODECol = outCursor.getColumnIndex("UGLYCODE");
int CLASSCODECol = outCursor.getColumnIndex("CLASSCODE");
int CLASSNAMECol = outCursor.getColumnIndex("CLASSNAME");
**int PHOTOCol = outCursor.getColumnIndex("PHOTO");
int ImageBase64Col = outCursor.getColumnIndex("ImageBase64");**
int DETAILCol = outCursor.getColumnIndex("DETAIL");
for (int i = 0; i < recordCount; i++) {
outCursor.moveToNext();
**BitmapDrawable drawable = (BitmapDrawable)ImageView1.getDrawable();
Bitmap bitmap = drawable.getBitmap();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, outStream);
byte[] image = outStream.toByteArray();
String ImageBase64 = Base64.encodeToString(image, 0);
String PHOTO = outCursor.getString(PHOTOCol);
byte[] bytePlainOrg = Base64.decode(PHOTO, 0);
ByteArrayInputStream inStream = new ByteArrayInputStream(bytePlainOrg);
Bitmap bm = BitmapFactory.decodeStream(inStream);
ImageView1.setImageBitmap(bm);**
String UGLYCODE = outCursor.getString(UGLYCODECol);
String CLASSCODE = outCursor.getString(CLASSCODECol);
String CLASSNAME = outCursor.getString(CLASSNAMECol);
String DETAIL = outCursor.getString(DETAILCol);
txtMsg.append("\n");
txtMsg.append("[" + CLASSNAME + "]\n");
txtMsg.append("\n");
txtMsg.append(DETAIL + "\n\n");
txtMsg.append("------------------------------------------------");
txtMsg.append("\n");
}
outCursor.close();
}
public void println(String msg) {
Log.d(TAG, msg);
}
}
这是错误日志:
06-01 01:32:57.198: I/dalvikvm-heap(1468): Grow heap (frag case) to 54.976MB for 9830416-byte allocation
06-01 01:32:57.368: D/dalvikvm(1468): GC_CONCURRENT freed 0K, 3% free 56200K/57415K, paused 13ms+17ms, total 167ms
06-01 01:32:57.458: D/uglyDetailActivity(1468): cursor count : 6
06-01 01:32:57.458: D/AndroidRuntime(1468): Shutting down VM
06-01 01:32:57.458: W/dalvikvm(1468): threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
06-01 01:32:57.458: E/AndroidRuntime(1468): FATAL EXCEPTION: main
06-01 01:32:57.458: E/AndroidRuntime(1468): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.aiden.excusemecomplete/org.aiden.excusemecomplete.uglyDetailActivity}: java.lang.NullPointerException
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.ActivityThread.access$600(ActivityThread.java:130)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.os.Looper.loop(Looper.java:137)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-01 01:32:57.458: E/AndroidRuntime(1468): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 01:32:57.458: E/AndroidRuntime(1468): at java.lang.reflect.Method.invoke(Method.java:511)
06-01 01:32:57.458: E/AndroidRuntime(1468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-01 01:32:57.458: E/AndroidRuntime(1468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-01 01:32:57.458: E/AndroidRuntime(1468): at dalvik.system.NativeStart.main(Native Method)
06-01 01:32:57.458: E/AndroidRuntime(1468): Caused by: java.lang.NullPointerException
06-01 01:32:57.458: E/AndroidRuntime(1468): at org.aiden.excusemecomplete.uglyDetailActivity.HandleCursorData(uglyDetailActivity.java:65)
06-01 01:32:57.458: E/AndroidRuntime(1468): at org.aiden.excusemecomplete.uglyDetailActivity.onCreate(uglyDetailActivity.java:44)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.Activity.performCreate(Activity.java:5008)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
06-01 01:32:57.458: E/AndroidRuntime(1468): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
06-01 01:32:57.458: E/AndroidRuntime(1468): ... 11 more
06-01 01:32:58.848: I/Process(1468): Sending signal. PID: 1468 SIG: 9
06-01 01:32:59.409: E/Trace(1513): error opening trace file: No such file or directory (2)
在添加粗体部分之前,此代码正常工作。我尝试将imageview添加到此数据库,它无法正常工作......