Android - How does it run and how to use eclipse?
This is probably two questions in one....
Firstly i wonder how does android run the code, is it step by step. The reason i ask this is because at the moment what i am trying to do is decrypt an image and them display it. However, the problem i think is that the code is adding the bitmap image too fast before it is decrypted. Should it run the code line by line?
Secondly Eclipse gives stack error etc but i dont know how to read the stack, is there a way to set it to just say this is the line in the code which is causing the problem?
thanks
EDIT
DesEncrypter encrypter = new DesEncrypter();
File Directory = new File(Environment.getExternalStorageDirectory()+"/Temp");
FileInputStream iFile = new FileInputStream(new File("/sdcard/Images/"+Id+".jpg"));
FileOutputStream fos = new FileOutputStream(Directory+"/"+Id+".jpg");
encrypter.frontDecrypt(iFile, fos);
File file = new File(Environment.getExternalStorageDirectory()+"/Temp/"+Id+".jpg");
if(file.exists()){
bm = BitmapFactory.decodeFi开发者_JAVA技巧le(Environment.getExternalStorageDirectory()+"/Temp/"+Id+".jpg");
}
else{
bm = BitmapFactory.decodeResource(getResources(), R.drawable.avatar);
}
}
catch(Exception e){}
iv.setImageBitmap(bm);
This code seems to work now and then, i think sometimes the bm isnt added correctly. Even if there is no image it should add one from the resource but does not do so.
You could probably learn more about what's going wrong if you don't swallow the exception like you're doing:
try {
// stuff...
} catch (Exception e) { }
Instead, at least log the exception:
private static final String TAG = "MyClass";
try {
// stuff...
} catch (Exception e)
{
android.util.Log.w(TAG, e);
}
Obviously code is executed line by line but there are some methods that runs async so they return immediately but execution still continues
You can always run your application with the debugger and go step by step. Set a breakpoint somewhere on your code and run the application with the debugger in eclipse...
精彩评论