-1

Everything was working fine till yesterday, and that out of nowhere appeared following problem. When Clicked ImageView , this image should be appear/display likely the detail of the image. But, in case when clicked ImageView the results is Unfortunately, App has stopped:

Display Images code:

   package com.vgm_versi2rev;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

import com.vgm_versi2rev.ImageResizer;
import com.vgm_versi2rev.R;
import com.vgm_versi2rev.MyImage;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

public class DisplayImage extends Activity{
    private MyImage image;
    private ImageView imageView;
    private TextView description;
    private String jstring;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_image);
        imageView = (ImageView) findViewById(R.id.display_image_view);
        description = (TextView) findViewById(R.id.text_view_description);
        Bundle extras = getIntent().getExtras();

        if (extras != null) {
            jstring = extras.getString("IMAGE");
        }
        image = getMyImage(jstring);
        description.setText(image.toString());
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;
        imageView.setImageBitmap(ImageResizer
                .decodeSampledBitmapFromFile(image.getPath(), width, height));
    }


    private MyImage getMyImage(String image) {
        try {
            JSONObject job = new JSONObject(image);
            return (new MyImage(job.getString("path"),job.getString("title"),
                    job.getString("datetime"),job.getString("description"),
                    job.getString("longitude"),job.getString("latitude")));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }


    public void btnBackOnClick(View v) {
        startActivity(new Intent(this, MainActivityPhoto.class));
        finish();
    }

    public void btnDeleteOnClick(View v) {
        DAOdb db = new DAOdb(this);
        db.deleteImage(image);
        db.close();
        startActivity(new Intent(this, MainActivityPhoto.class));
        finish();
    }

    @Override protected void onSaveInstanceState(Bundle outState) {
        // Save the user's current game state
        if (jstring != null) {
            outState.putString("jstring", jstring);
        }
        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(outState);
    }

    @Override protected void onRestoreInstanceState(Bundle savedInstanceState) {
        // Always call the superclass so it can restore the view hierarchy
        super.onRestoreInstanceState(savedInstanceState);

        // Restore state members from saved instance
        if (savedInstanceState.containsKey("jstring")) {
            jstring = savedInstanceState.getString("jstring");
        }
    }
}

Error which is returned when I press the Display Image (ImageView):

> 04-29 09:36:00.417: E/AndroidRuntime(30734): FATAL EXCEPTION: main
> 04-29 09:36:00.417: E/AndroidRuntime(30734):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.vgm_versi2rev/com.vgm_versi2rev.DisplayImage}:
> java.lang.NullPointerException 04-29 09:36:00.417:
> E/AndroidRuntime(30734):  at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  at
> android.app.ActivityThread.access$700(ActivityThread.java:159) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  at
> android.os.Handler.dispatchMessage(Handler.java:99) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> android.os.Looper.loop(Looper.java:137) 04-29 09:36:00.417:
> E/AndroidRuntime(30734):  at
> android.app.ActivityThread.main(ActivityThread.java:5419) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> java.lang.reflect.Method.invokeNative(Native Method) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> java.lang.reflect.Method.invoke(Method.java:525) 04-29 09:36:00.417:
> E/AndroidRuntime(30734):  at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> dalvik.system.NativeStart.main(Native Method) 04-29 09:36:00.417:
> E/AndroidRuntime(30734): Caused by: java.lang.NullPointerException
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  at
> com.vgm_versi2rev.DisplayImage.onCreate(DisplayImage.java:56) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> android.app.Activity.performCreate(Activity.java:5372) 04-29
> 09:36:00.417: E/AndroidRuntime(30734):    at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
> 04-29 09:36:00.417: E/AndroidRuntime(30734):  ... 11 more

My Android Manifest is below :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.vgm_versi2rev"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="14" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
     <uses-feature
        android:name="android.hardware.camera"
        android:required="false"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/vgm"
        android:label="@string/app_name"
         android:theme="@style/AppTheme" >

         <activity
            android:name=".Homepage"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Lihat_Data"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DetailActivity">

        </activity>

        <activity
            android:name=".MainActivityPetiole"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

       <activity
            android:name=".MainActivityPhoto"
            android:label="@string/app_name">
            <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DisplayImage"

            android:label="@string/title_activity_display_image"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        </activity>


    </application>

</manifest>

Help would me much appreciated! Best Regards

Sa Sya
  • 21
  • 6

1 Answers1

0

The error line is 56 : description.setText(image.toString());

and I check you function getMyImage(String image) it's seem like you got a loop in this function,

private MyImage getMyImage(String image) {
    try {
        JSONObject job = new JSONObject(image);
        return (new MyImage(job.getString("path"),job.getString("title"),
                job.getString("datetime"),job.getString("description"),
                job.getString("longitude"),job.getString("latitude")));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

a function return itself with different parameters,I got a little confused,But the problem there may be in this