Wednesday, 11 September 2013

java.io.FileNotFoundException:

java.io.FileNotFoundException:

I am currently working on someone else's project as they have left the
company. I am only on a internship and java isn't my strong subject.
Basically the application works from receiving the information from a feed
and places that information in the relevant places.
However the client as asked for a graphic to be place on the images which
have the let agreed.
This is has been done for me as i don't have any accesses to the feed.
I would like to point out that the feed with the graphic is working
perfectly fine on the iPhone app.
Upon pressing the search button this message prints out in my log cat:
java.io.FileNotFoundException:
http://images.ultrait.me/ImageProcessor.aspx?imageURL=381/Sales/321470/53659_T_ADDRESSES_52050_TN.jpg&Text=LET
AGREED
As you can see from clicking the link the icon appears.
When i click on to the tab to search for properties the feed will begin to
load, and the images will appear in a list view. The images will appear
but it doesn't have the let agreed icon on it, i believe it is because it
is placing image one from the feed as the thumbnail, but i need it to
display the graphic(I'm not sure if this is even correct).
When i click to view a property the image disappears.
I am working to a deadline and i have noone to help me out. Please be
patient with me.
Here are some of my classes which i think you might need to see.
public class _06_Photos extends Activity implements ViewFactory{
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
//GUI Components
TextView tv_counter;
//ImageView iv_activity;
ImageSwitcher imageSwitcher;
Button b_play;
Button b_next;
Button b_previous;
FrameLayout topFrame, bottomFrame;
//Images and Stuff
String [] str_imageURLs;
Bitmap [] bm_images;
int picNum = 0;
boolean play;
boolean stop;
Handler handler;
Thread playThread;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xl_06_photos);
handler = new Handler();
playThread = new Thread(Play);
play = false;
stop = false;
playThread.start();
str_imageURLs = new String[5];
for(int i=0; i<5;++i)
str_imageURLs[i] = "";
bm_images = new Bitmap[5];
InitView();
Bundle extras = getIntent().getExtras();
if (extras != null) {
str_imageURLs[0] = extras.getString("img1");
str_imageURLs[1] = extras.getString("img2");
str_imageURLs[2] = extras.getString("img3");
str_imageURLs[3] = extras.getString("img4");
str_imageURLs[4] = extras.getString("img5");
}
for(int i=0; i<5; i++)
System.out.println(str_imageURLs[i]);
new Thread(new Runnable() {
public void run() {
for(int i=0; i<5; ++i)
{
try{
bm_images[i] =
FindPropertyActivity.DownloadImage(str_imageURLs[i]);
}
catch(Exception e){
System.out.println("Image" + i + " not downloaded
- " + e);
}
try{
if(bm_images[i] == null)
{
System.out.println("Bitmap " + i + " is null");
bm_images[i] =
BitmapFactory.decodeResource(getResources(),
R.drawable.download_error);
}
if(picNum == i)
//iv_activity.setVisibility(View.INVISIBLE);
//Drawable d =new BitmapDrawable(bm_images[i]);
//imageSwitcher.setImageDrawable(d);
handler.post(SetPic);
}
catch(Exception e){
System.out.println("PicNum null/visiablity" + i +
" not setCorrectly - " + e);
}
}
System.gc();
}
}).start();
}
private void InitView(){
handler.post(SetPic);
tv_counter = (TextView)findViewById(R.id.photo_tv_counter);
imageSwitcher =
(ImageSwitcher)findViewById(R.id.photo_imageSwitcher);
imageSwitcher.setFactory(this);
topFrame = (FrameLayout)findViewById(R.id.photo_topFrame);
bottomFrame = (FrameLayout)findViewById(R.id.photo_bottomFrame);
final GestureDetector gestureDetector = new GestureDetector(new
MyGestureDetector());
imageSwitcher.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
return true;
}
});
b_play = (Button)findViewById(R.id.photo_b_play);
if(play){
b_play.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_pause));
topFrame.setVisibility(View.INVISIBLE);
bottomFrame.setVisibility(View.INVISIBLE);
}
else{
b_play.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_play));
}
b_play.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Drawable background = v.getBackground();
background.setColorFilter(0xFF7A7A7A,
PorterDuff.Mode.MULTIPLY);
v.setBackgroundDrawable(background);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
Drawable background = v.getBackground();
background.setColorFilter(null);
v.setBackgroundDrawable(background);
if(play){
play = false;
b_play.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_play));
}
else{
play = true;
b_play.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_pause));
topFrame.setVisibility(View.INVISIBLE);
bottomFrame.setVisibility(View.INVISIBLE);
}
}
return false;
}
});
b_previous = (Button)findViewById(R.id.photo_b_previous);
b_previous.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Drawable background = v.getBackground();
background.setColorFilter(0xFF7A7A7A,
PorterDuff.Mode.MULTIPLY);
v.setBackgroundDrawable(background);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
Drawable background = v.getBackground();
background.setColorFilter(null);
v.setBackgroundDrawable(background);
PreviousPic();
}
return false;
}
});
b_next = (Button)findViewById(R.id.photo_b_next);
b_next.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Drawable background = v.getBackground();
background.setColorFilter(0xFF7A7A7A,
PorterDuff.Mode.MULTIPLY);
v.setBackgroundDrawable(background);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
Drawable background = v.getBackground();
background.setColorFilter(null);
v.setBackgroundDrawable(background);
NextPic();
}
return false;
}
});
}
public void onDestroy(){
super.onDestroy();
stop = true;
}
private final Runnable SetPic = new Runnable() {
public void run() {
//iv_activity.setVisibility(View.INVISIBLE);
Drawable d =new BitmapDrawable(bm_images[picNum]);
imageSwitcher.setImageDrawable(d);
System.out.println("Pic Set");
tv_counter.setText("" + (picNum+1) + "/5");
}
};
private final Runnable Play = new Runnable() {
public void run() {
while(!stop){
try{
Thread.sleep(3000);
handler.post(new Runnable() {
public void run() {
if(play)
NextPic();
}
});
}
catch(Exception e){
System.out.println("Play Error - " + e);
}
}
}
};
protected void NextPic(){
try{
picNum++;
if(picNum > 4)
picNum = 0;
tv_counter.setText("" + (picNum+1) + "/5");
imageSwitcher.setInAnimation(this, R.anim.slide_in_left ); //
added
imageSwitcher.setOutAnimation(this, R.anim.slide_out_left); //
added
Drawable d =new BitmapDrawable(bm_images[picNum]);
imageSwitcher.setImageDrawable(d);
System.out.println("Next Pic");
}
catch(Exception e){
System.out.println("Next Fail " + e);
imageSwitcher.setImageDrawable(null);
}
}
protected void PreviousPic(){
picNum--;
if(picNum < 0)
picNum = 4;
tv_counter.setText("" + (picNum+1) + "/5");
try{
imageSwitcher.setInAnimation(this, R.anim.slide_in_right ); //
added
imageSwitcher.setOutAnimation(this, R.anim.slide_out_right);
// added
Drawable d =new BitmapDrawable(bm_images[picNum]);
imageSwitcher.setImageDrawable(d);
System.out.println("Previous Pic");
}
catch(Exception e){
System.out.println("Previous Fail " + e);
//imageSwitcher.setImageResource(R.drawable.download_error);
imageSwitcher.setImageDrawable(null);
}
}
protected void ChangeBarVisibles(){
if(topFrame.isShown()){
topFrame.setVisibility(View.INVISIBLE);
bottomFrame.setVisibility(View.INVISIBLE);
}
else{
topFrame.setVisibility(View.VISIBLE);
bottomFrame.setVisibility(View.VISIBLE);
}
}
public View makeView()
{
ImageView imageView = new ImageView(this);
imageView.setBackgroundColor(0xFF000000);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new
ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
return imageView;
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//Toast.makeText(SelectFilterActivity.this, "Left
Swipe", Toast.LENGTH_SHORT).show();
NextPic();
//return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//Toast.makeText(SelectFilterActivity.this, "Right
Swipe", Toast.LENGTH_SHORT).show();
PreviousPic();
//return true;
}
} catch (Exception e) {
// nothing
}
return true;
}
public boolean onSingleTapUp(MotionEvent e){
if(e.getAction() == MotionEvent.ACTION_UP){
ChangeBarVisibles();
}
return true;
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.xl_06_photos);
InitView();
}
@Override
public void onStop(){
super.onStop();
System.gc();
}
}
My results class :
public class _02_Results extends ListActivity {
private SearchParser xmlParser;
private URLQueryGenerator urlGen;
//private ProgressDialog dialog;
private Handler handler;
private CellAdapter_SearchResults adapter;
//private Thread thr_downloadImages;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xl_02_results);
handler = new Handler();
//thr_downloadImages = new Thread();
xmlParser = new SearchParser();
urlGen = new URLQueryGenerator(getParent());
adapter =new CellAdapter_SearchResults(_02_Results.this,
AppDelegate.properties);
setListAdapter(adapter);
if(AppDelegate.properties.size() < 1){
//Reset Results page number to one. Because the results are
starting afresh.
AppDelegate.pageNum = 1;
handler.post(ReloadCells);
GetResults();
}
if(AppDelegate.results_ListView_State != null)
getListView().onRestoreInstanceState(AppDelegate.results_ListView_State);
//if(AppDelegate.pick > 0)
// setSelection(AppDelegate.pick);
}
public void onResume()
{
super.onResume();
System.gc();
new Thread(LoadImages).start();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long
id) {
//If the last is picked and it is a Get More (Blank/Empty) Cell
Download More Properties.
if(position >= AppDelegate.properties.size()-1 &&
AppDelegate.properties.get(position).str_ID.length() <= 0)
{
xmlParser = new SearchParser();
LoadMoreResults();
}
//Else view Property in Array
else{
Intent myIntent = new Intent(getParent(), _03_Detailed.class);
AppDelegate.pick = position;
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("Detailed_03", myIntent);
//Save the listview state for later init
AppDelegate.results_ListView_State =
getListView().onSaveInstanceState();
}
}
protected void GetResults(){
//Show Progress Dialog
//dialog = ProgressDialog.show(getParent(), "",
getResources().getString(R.string.search_alert), true);
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.search_alert),
Toast.LENGTH_SHORT).show();
Runnable getResults = new Runnable() {
public void run() {
try{
//Get XML page from URL generated as a String
String xml =
XMLfunctions.getXML(urlGen.createSearchURL());
if(xml == null){
handler.post(DownloadFail_Dialog);
System.out.println("xml is null");
return;
}
//Add the parsed properties return from Parser
AppDelegate.properties.addAll(xmlParser.ParserXML(xml));//
xmlParser.ParserXML(urlString);
//Get the number of results for search
if(AppDelegate.numResults < 0)
AppDelegate.numResults = xmlParser.numResults;
System.out.println("Numb of Results:- " +
AppDelegate.numResults);
//Add blank cell for more button
if(AppDelegate.properties.size() < xmlParser.numResults)
AppDelegate.properties.add(new Property());
//Refresh the ListView
try{handler.post(ReloadCells);}
catch(Exception e) { System.out.println(e);}
//dialog.dismiss();
if(AppDelegate.properties.size() < 1)
handler.post(NoResults_Dialog);
}
catch(Exception e){
//dialog.dismiss();
handler.post(DownloadFail_Dialog);
System.out.println(e);
}
finally{
//Dismiss Progress dialog
//dialog.dismiss();
System.gc();
new Thread(LoadImages).start();
}
}
};
new Thread(getResults).start();
}
protected void LoadMoreResults()
{
//Only proceed if more results are available
if(AppDelegate.numResults > AppDelegate.properties.size()){
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.search_more),
Toast.LENGTH_SHORT).show();
//Show progress dialog
//dialog = ProgressDialog.show(getParent(), "",
getResources().getString(R.string.loading), true);
Runnable getResults = new Runnable() {
public void run() {
try{
AppDelegate.pageNum++;
String xml = null;
//Get XML Page as a String
xml = XMLfunctions.getXML(urlGen.createSearchURL()
+ "&Page=" + AppDelegate.pageNum);
if(xml == null){
handler.post(DownloadFail_Dialog);
System.out.println("xml is null");
return;
}
//Add properties returned from XML Parser
AppDelegate.properties.addAll(AppDelegate.properties.size()-1,
xmlParser.ParserXML(xml));//
xmlParser.ParserXML(urlString);
handler.post(ReloadCells);
}
catch(Exception e){
System.out.println(e);
AppDelegate.pageNum--;
//dialog.dismiss();
}
finally{
//dialog.dismiss();
System.gc();
/*
if(thr_downloadImages.isAlive()){
thr_downloadImages.stop();
thr_downloadImages = null;
}
thr_downloadImages = new Thread(LoadImages);
thr_downloadImages.start();
*/
new Thread(LoadImages).start();
}
}
};
new Thread(getResults).start();
}
else{
handler.post(NoResults_Dialog);
}
}
/**
* **IMPORTANT**
*
* The functions below are for the activity to be accessed at any point.
* They should only be access by Handler.
*
* By using the handler, this can be accessed from inside a separate
Thread other than the Main one.
* This is done because some GUI elements can not be accessed inside
a Thread, other than the Main.
*
*/
private final Runnable LoadImages = new Runnable() {
public void run() {
for(int x=0; x <AppDelegate.properties.size(); x++){
try{
//Run the image download twice, because sometimes the
images doesn't download the first time
if(AppDelegate.properties.get(x).img_thumb == null)
AppDelegate.properties.get(x).img_thumb =
FindPropertyActivity.DownloadImage(AppDelegate.properties.get(x).str_imgURL1);
if(AppDelegate.properties.get(x).img_thumb == null)
AppDelegate.properties.get(x).img_thumb =
FindPropertyActivity.DownloadImage(AppDelegate.properties.get(x).str_imgURL1);
handler.post(ReloadCells);
}
catch (Exception e) {System.out.println(e.toString());}
}
}
};
private final Runnable ReloadCells = new Runnable() {
public void run() {
adapter.UpdateDataSet(AppDelegate.properties);
adapter.notifyDataSetChanged();
}
};
private final Runnable DownloadFail_Dialog = new Runnable() {
public void run() {
AlertDialog.Builder builder = new
AlertDialog.Builder(getParent());
builder.setMessage(getResources().getString(R.string.download_fail))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do nothing
}
});
AlertDialog alert = builder.create();
alert.show();
}
};
private final Runnable NoResults_Dialog = new Runnable() {
public void run() {
AlertDialog.Builder builder = new
AlertDialog.Builder(getParent());
builder.setMessage(getResources().getString(R.string.no_results))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do nothing
}
});
AlertDialog alert = builder.create();
alert.show();
}
};
}
I dont have any more room to paste another class :(
Any help is appreciated.
Thank you in advance!!

No comments:

Post a Comment