I am attempting to display an image on a popup window, however I have ran into problems and cannot see why this is. I have pinpointed the line of code that makes my app crash, also I have been trying to follow another post which shows how to create a popup window here However my situation is only slightly different because I am trying to get my image from a file path. I am sorry if this is not clear as I am not very good at explaining
private void listClick(){
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parentView, View childView,
int position, long id) {
String selectedItem = list.getItemAtPosition(position).toString();
String imgFilePath = dataBank.get(selectedItem);
File imgFile = new File(imgFilePath);
if(imgFile.exists()){
String absFilePath = imgFile.getAbsolutePath();
loadPhoto(absFilePath, 10, 10);
}
Toast.makeText(context, selectedItem, duration).show();
}
});
}
private void loadPhoto(String filepath, int width, int height){
Log.d("FAILS", "1");
AlertDialog.Builder imageDialog = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
Log.d("FAILS", "2");
View layout = inflater.inflate(R.layout.custom_fullimage_dialog,
(ViewGroup)findViewById(R.id.layout_root));
ImageView image = (ImageView)findViewById(R.id.fullimage);
Log.d("FAILS", "3");
image.setImageBitmap(BitmapFactory.decodeFile(filepath));
Log.d("FAILS", "4");
imageDialog.setView(layout);
imageDialog.setPositiveButton("Return", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
imageDialog.create();
imageDialog.show();
}
and here is my custom_fullimage_dialog xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp">
<ImageView
android:id="@+id/fullimage"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
</ImageView>
<TextView android:id="@+id/custom_fullimage_placename"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textColor="#FFF">
</TextView>
</LinearLayout>
Here is my activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.igauto.MainActivity"
tools:ignore="MergeRootFrame" />
and here is my fragment_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.igauto.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_user" />
<EditText
android:id="@+id/user_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/userText"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="selectImage"
android:text="@string/button_image" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="@string/button_send" />
<ListView
android:id="@+id/myList"
android:layout_width="wrap_content"
android:layout_height="120dp" >
</ListView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="tempEdit"
android:text="@string/button_Edit" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
I believe the line it crashes on is within the loadPhoto method as in the log it shows 1 2 and 3 from the log.d()'s I have put up.
image.setImageBitmap(BitmapFactory.decodeFile(filepath));