E/AndroidRuntime: FATAL EXCEPTION: main, my app is keep on closing when camera button is clicked,2019 Community Moderator ElectionWhat is a NullPointerException, and how do I fix it?How to prevent a dialog from closing when a button is clickedAndroidRuntime(1130): FATAL EXCEPTION: mainE/AndroidRuntime﹕ FATAL EXCEPTION: mainE/AndroidRuntime﹕ FATAL EXCEPTION: mainAndroidRuntime FATAL EXCEPTION: MainAndroidRuntime﹕ FATAL EXCEPTION: main (libGDXE/AndroidRuntime: FATAL EXCEPTION: mainAndroidRuntime: FATAL EXCEPTION: mainE/AndroidRuntime﹕ FATAL EXCEPTION: mainE/AndroidRuntime: FATAL EXCEPTION: main (when clicking a button app crashes)

Why one should not leave fingerprints on bulbs and plugs?

What approach do we need to follow for projects without a test environment?

Life insurance that covers only simultaneous/dual deaths

Why is the President allowed to veto a cancellation of emergency powers?

Dice rolling probability game

What is a^b and (a&b)<<1?

Can I use USB data pins as power source

Gravity magic - How does it work?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Does Mathematica reuse previous computations?

Is it normal that my co-workers at a fitness company criticize my food choices?

Time travel from stationary position?

how to write formula in word in latex

Python if-else code style for reduced code for rounding floats

Why Choose Less Effective Armour Types?

Are there verbs that are neither telic, or atelic?

Brexit - No Deal Rejection

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Unexpected result from ArcLength

How to create the Curved texte?

Have researchers managed to "reverse time"? If so, what does that mean for physics?

Identifying the interval from A♭ to D♯

Bach's Toccata and Fugue in D minor breaks the "no parallel octaves" rule?

How could a scammer know the apps on my phone / iTunes account?



E/AndroidRuntime: FATAL EXCEPTION: main, my app is keep on closing when camera button is clicked,



2019 Community Moderator ElectionWhat is a NullPointerException, and how do I fix it?How to prevent a dialog from closing when a button is clickedAndroidRuntime(1130): FATAL EXCEPTION: mainE/AndroidRuntime﹕ FATAL EXCEPTION: mainE/AndroidRuntime﹕ FATAL EXCEPTION: mainAndroidRuntime FATAL EXCEPTION: MainAndroidRuntime﹕ FATAL EXCEPTION: main (libGDXE/AndroidRuntime: FATAL EXCEPTION: mainAndroidRuntime: FATAL EXCEPTION: mainE/AndroidRuntime﹕ FATAL EXCEPTION: mainE/AndroidRuntime: FATAL EXCEPTION: main (when clicking a button app crashes)










-4















public class CameraActivity extends AppCompatActivity implements View.OnClickListener



static 
System.loadLibrary("opencv_java3");
String TAG = "OpenCVLibrary";
if(!OpenCVLoader.initDebug())
Log.d(TAG,"OpenCv Not Successfully Loaded");
else
Log.d(TAG,"OpenCv Successfully Loaded");


private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
DBController db;
ImageProcessing imgproc;
Button btnProcess;
Cursor res;
ProgressDialog progressDialog;
ImageView imgTaken;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
// Objects.requireNonNull(getSupportActionBar()).setTitle("Camera");
OpenCVLoader.initDebug();
//Initialize View
imgTaken = findViewById(R.id.imgTaken);
btnProcess = findViewById(R.id.btnProcess);
btnProcess.setEnabled(false);
Button btnBack = findViewById(R.id.btnBack);
//Create a Bitmap of the Image captured using camera
//imgTaken.setImageBitmap(getTakenImage());
//Set OnClick Listener
btnBack.setOnClickListener(this);
btnProcess.setOnClickListener(this);



public void process()
final String TAG = "Image Processing";
progressDialog = new ProgressDialog(CameraActivity.this);

final ArrayList<ProcessResult> processResults = new ArrayList<>();
db = new DBController(this);
imgproc = new ImageProcessing();
AsyncTask<String,String,String> task = new AsyncTask<String, String, String>()
@Override
protected void onPreExecute()
super.onPreExecute();
//Processing Dialog

progressDialog.setMessage("Processing Image nPlease wait!...");
progressDialog.setCancelable(false);
progressDialog.show();



@Override
protected String doInBackground(String... strings)
/*Compute for the Match Percentage of the Image
compareFeature Method
First Params = Parasite Image
Second Params = Image Taken

Retrieve all Parasite Image in the Database
*/
try
res = db.getAllData("tbl_succulentsinfo");
Log.d(TAG, "" + res.getCount());

if (res.moveToFirst())
//String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.thesis.app.parafish/files/" + res.getString(2);
//Bitmap tmpbmp = BitmapFactory.decodeFile(file);
int rate = 0;

Log.d(TAG,rate+"");
do
Log.e(TAG, res.getString(0) + "/" + res.getString(1) + "/" + res.getString(2)+ "/" + res.getString(3)+ "/" + res.getString(4));
String imgpath = res.getString(3);
String[] newimgpath = imgpath.split("/");
String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.example.geraldine.succulentidentifierapplication/files/" + newimgpath[1];
Bitmap tmpbmp = BitmapFactory.decodeFile(file);

ProcessResult result = new ProcessResult();

if(tmpbmp!=null &&getTakenImage()!=null)

rate = compareFeature(tmpbmp, getTakenImage());


Log.d(TAG, rate + "");
result.setSucculentID(res.getString(0));
result.setResult(rate);
processResults.add(result);

while (res.moveToNext());


catch (Exception e)
e.printStackTrace();

Log.d(TAG,"here");
Collections.sort(processResults, new ArraySort());
/*Rearrange the Top 3 Best Match. Result with the same Parasite ID with the highest Match
remain while the other one will be remove from the list
By doing this ArrayList with Index from 0-2 is now the Top 3 Match with different parasite id
*/
for(int i = 0; i < processResults.size(); i++)
Log.d("Top3",processResults.get(i).getResult().toString());

int index = 0;
for(int i = 0; i < processResults.size()-1; i++)
ProcessResult result1 = processResults.get(i);
for(int y=i+1;y < (processResults.size()-1)-i;y++)
ProcessResult result2 = processResults.get(y);
Log.d("Top3",result1.getSucculentID()+" Compared to "+result2.getSucculentID());
if(result1.getSucculentID().equals(result2.getSucculentID()))
processResults.remove(i+1);



for(int i = 0; i < processResults.size(); i++)
Log.d("Top3","ID="+processResults.get(i).getSucculentID()+" Rate:"+processResults.get(i).getResult().toString());

return null;


@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
progressDialog.dismiss();

//tempo
Intent intent = new Intent(CameraActivity.this, Match.class);

intent.putExtra("top1",processResults.get(0).getSucculentID());
intent.putExtra("percentage1",processResults.get(0).getResult()+"");
Log.d("Top1","ID="+processResults.get(0).getSucculentID()+" Rate:"+processResults.get(0).getResult().toString());

intent.putExtra("top2",processResults.get(1).getSucculentID());
intent.putExtra("percentage2",processResults.get(1).getResult()+"");
Log.d("Top2","ID="+processResults.get(1).getSucculentID()+" Rate:"+processResults.get(1).getResult().toString());

intent.putExtra("top3",processResults.get(2).getSucculentID());
intent.putExtra("percentage3",processResults.get(2).getResult()+"");
Log.d("Top3","ID="+processResults.get(2).getSucculentID()+" Rate:"+processResults.get(2).getResult().toString());

intent.putExtra("from","ProcessImage");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

;
task.execute("");


public Bitmap getTakenImage()
//String path = getApplicationContext().getExternalFilesDir(null).toString()+"/pic.jpg";
Bitmap bmp = ((BitmapDrawable) imgTaken.getDrawable()).getBitmap();
return bmp;

@Override
public boolean onOptionsItemSelected(MenuItem item)
finish();
return true;




@Override
public void onClick(View view)
switch (view.getId())
case R.id.btnProcess:
Cursor res;
db = new DBController(this);

process();
break;
case R.id.btnBack:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
//finish();
break;
default:
break;



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
if (resultCode == RESULT_OK)
Bitmap bp = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");

new Utility(CameraActivity.this).SaveTemp(bp,""+1);
btnProcess.setEnabled(true);
imgTaken.setImageBitmap(bp);
else if (resultCode == RESULT_CANCELED)
// User cancelled the image capture
else
// Image capture failed, advise user




public int compareFeature(Bitmap bmp1, Bitmap bmp2)




LOGCAT



E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.geraldine.succulentidentifierapplication, PID: 3652
java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.geraldine.succulentidentifierapplication/com.example.geraldine.succulentidentifierapplication.CameraActivity: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at com.example.geraldine.succulentidentifierapplication.CameraActivity.onCreate(CameraActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6666)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6251) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 










share|improve this question



















  • 2





    Possible duplicate of What is a NullPointerException, and how do I fix it?

    – Tamir Abutbul
    Mar 7 at 14:21











  • i'm having a problem with this Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

    – Geraldine Cruz
    Mar 8 at 2:13















-4















public class CameraActivity extends AppCompatActivity implements View.OnClickListener



static 
System.loadLibrary("opencv_java3");
String TAG = "OpenCVLibrary";
if(!OpenCVLoader.initDebug())
Log.d(TAG,"OpenCv Not Successfully Loaded");
else
Log.d(TAG,"OpenCv Successfully Loaded");


private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
DBController db;
ImageProcessing imgproc;
Button btnProcess;
Cursor res;
ProgressDialog progressDialog;
ImageView imgTaken;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
// Objects.requireNonNull(getSupportActionBar()).setTitle("Camera");
OpenCVLoader.initDebug();
//Initialize View
imgTaken = findViewById(R.id.imgTaken);
btnProcess = findViewById(R.id.btnProcess);
btnProcess.setEnabled(false);
Button btnBack = findViewById(R.id.btnBack);
//Create a Bitmap of the Image captured using camera
//imgTaken.setImageBitmap(getTakenImage());
//Set OnClick Listener
btnBack.setOnClickListener(this);
btnProcess.setOnClickListener(this);



public void process()
final String TAG = "Image Processing";
progressDialog = new ProgressDialog(CameraActivity.this);

final ArrayList<ProcessResult> processResults = new ArrayList<>();
db = new DBController(this);
imgproc = new ImageProcessing();
AsyncTask<String,String,String> task = new AsyncTask<String, String, String>()
@Override
protected void onPreExecute()
super.onPreExecute();
//Processing Dialog

progressDialog.setMessage("Processing Image nPlease wait!...");
progressDialog.setCancelable(false);
progressDialog.show();



@Override
protected String doInBackground(String... strings)
/*Compute for the Match Percentage of the Image
compareFeature Method
First Params = Parasite Image
Second Params = Image Taken

Retrieve all Parasite Image in the Database
*/
try
res = db.getAllData("tbl_succulentsinfo");
Log.d(TAG, "" + res.getCount());

if (res.moveToFirst())
//String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.thesis.app.parafish/files/" + res.getString(2);
//Bitmap tmpbmp = BitmapFactory.decodeFile(file);
int rate = 0;

Log.d(TAG,rate+"");
do
Log.e(TAG, res.getString(0) + "/" + res.getString(1) + "/" + res.getString(2)+ "/" + res.getString(3)+ "/" + res.getString(4));
String imgpath = res.getString(3);
String[] newimgpath = imgpath.split("/");
String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.example.geraldine.succulentidentifierapplication/files/" + newimgpath[1];
Bitmap tmpbmp = BitmapFactory.decodeFile(file);

ProcessResult result = new ProcessResult();

if(tmpbmp!=null &&getTakenImage()!=null)

rate = compareFeature(tmpbmp, getTakenImage());


Log.d(TAG, rate + "");
result.setSucculentID(res.getString(0));
result.setResult(rate);
processResults.add(result);

while (res.moveToNext());


catch (Exception e)
e.printStackTrace();

Log.d(TAG,"here");
Collections.sort(processResults, new ArraySort());
/*Rearrange the Top 3 Best Match. Result with the same Parasite ID with the highest Match
remain while the other one will be remove from the list
By doing this ArrayList with Index from 0-2 is now the Top 3 Match with different parasite id
*/
for(int i = 0; i < processResults.size(); i++)
Log.d("Top3",processResults.get(i).getResult().toString());

int index = 0;
for(int i = 0; i < processResults.size()-1; i++)
ProcessResult result1 = processResults.get(i);
for(int y=i+1;y < (processResults.size()-1)-i;y++)
ProcessResult result2 = processResults.get(y);
Log.d("Top3",result1.getSucculentID()+" Compared to "+result2.getSucculentID());
if(result1.getSucculentID().equals(result2.getSucculentID()))
processResults.remove(i+1);



for(int i = 0; i < processResults.size(); i++)
Log.d("Top3","ID="+processResults.get(i).getSucculentID()+" Rate:"+processResults.get(i).getResult().toString());

return null;


@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
progressDialog.dismiss();

//tempo
Intent intent = new Intent(CameraActivity.this, Match.class);

intent.putExtra("top1",processResults.get(0).getSucculentID());
intent.putExtra("percentage1",processResults.get(0).getResult()+"");
Log.d("Top1","ID="+processResults.get(0).getSucculentID()+" Rate:"+processResults.get(0).getResult().toString());

intent.putExtra("top2",processResults.get(1).getSucculentID());
intent.putExtra("percentage2",processResults.get(1).getResult()+"");
Log.d("Top2","ID="+processResults.get(1).getSucculentID()+" Rate:"+processResults.get(1).getResult().toString());

intent.putExtra("top3",processResults.get(2).getSucculentID());
intent.putExtra("percentage3",processResults.get(2).getResult()+"");
Log.d("Top3","ID="+processResults.get(2).getSucculentID()+" Rate:"+processResults.get(2).getResult().toString());

intent.putExtra("from","ProcessImage");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

;
task.execute("");


public Bitmap getTakenImage()
//String path = getApplicationContext().getExternalFilesDir(null).toString()+"/pic.jpg";
Bitmap bmp = ((BitmapDrawable) imgTaken.getDrawable()).getBitmap();
return bmp;

@Override
public boolean onOptionsItemSelected(MenuItem item)
finish();
return true;




@Override
public void onClick(View view)
switch (view.getId())
case R.id.btnProcess:
Cursor res;
db = new DBController(this);

process();
break;
case R.id.btnBack:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
//finish();
break;
default:
break;



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
if (resultCode == RESULT_OK)
Bitmap bp = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");

new Utility(CameraActivity.this).SaveTemp(bp,""+1);
btnProcess.setEnabled(true);
imgTaken.setImageBitmap(bp);
else if (resultCode == RESULT_CANCELED)
// User cancelled the image capture
else
// Image capture failed, advise user




public int compareFeature(Bitmap bmp1, Bitmap bmp2)




LOGCAT



E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.geraldine.succulentidentifierapplication, PID: 3652
java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.geraldine.succulentidentifierapplication/com.example.geraldine.succulentidentifierapplication.CameraActivity: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at com.example.geraldine.succulentidentifierapplication.CameraActivity.onCreate(CameraActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6666)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6251) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 










share|improve this question



















  • 2





    Possible duplicate of What is a NullPointerException, and how do I fix it?

    – Tamir Abutbul
    Mar 7 at 14:21











  • i'm having a problem with this Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

    – Geraldine Cruz
    Mar 8 at 2:13













-4












-4








-4








public class CameraActivity extends AppCompatActivity implements View.OnClickListener



static 
System.loadLibrary("opencv_java3");
String TAG = "OpenCVLibrary";
if(!OpenCVLoader.initDebug())
Log.d(TAG,"OpenCv Not Successfully Loaded");
else
Log.d(TAG,"OpenCv Successfully Loaded");


private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
DBController db;
ImageProcessing imgproc;
Button btnProcess;
Cursor res;
ProgressDialog progressDialog;
ImageView imgTaken;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
// Objects.requireNonNull(getSupportActionBar()).setTitle("Camera");
OpenCVLoader.initDebug();
//Initialize View
imgTaken = findViewById(R.id.imgTaken);
btnProcess = findViewById(R.id.btnProcess);
btnProcess.setEnabled(false);
Button btnBack = findViewById(R.id.btnBack);
//Create a Bitmap of the Image captured using camera
//imgTaken.setImageBitmap(getTakenImage());
//Set OnClick Listener
btnBack.setOnClickListener(this);
btnProcess.setOnClickListener(this);



public void process()
final String TAG = "Image Processing";
progressDialog = new ProgressDialog(CameraActivity.this);

final ArrayList<ProcessResult> processResults = new ArrayList<>();
db = new DBController(this);
imgproc = new ImageProcessing();
AsyncTask<String,String,String> task = new AsyncTask<String, String, String>()
@Override
protected void onPreExecute()
super.onPreExecute();
//Processing Dialog

progressDialog.setMessage("Processing Image nPlease wait!...");
progressDialog.setCancelable(false);
progressDialog.show();



@Override
protected String doInBackground(String... strings)
/*Compute for the Match Percentage of the Image
compareFeature Method
First Params = Parasite Image
Second Params = Image Taken

Retrieve all Parasite Image in the Database
*/
try
res = db.getAllData("tbl_succulentsinfo");
Log.d(TAG, "" + res.getCount());

if (res.moveToFirst())
//String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.thesis.app.parafish/files/" + res.getString(2);
//Bitmap tmpbmp = BitmapFactory.decodeFile(file);
int rate = 0;

Log.d(TAG,rate+"");
do
Log.e(TAG, res.getString(0) + "/" + res.getString(1) + "/" + res.getString(2)+ "/" + res.getString(3)+ "/" + res.getString(4));
String imgpath = res.getString(3);
String[] newimgpath = imgpath.split("/");
String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.example.geraldine.succulentidentifierapplication/files/" + newimgpath[1];
Bitmap tmpbmp = BitmapFactory.decodeFile(file);

ProcessResult result = new ProcessResult();

if(tmpbmp!=null &&getTakenImage()!=null)

rate = compareFeature(tmpbmp, getTakenImage());


Log.d(TAG, rate + "");
result.setSucculentID(res.getString(0));
result.setResult(rate);
processResults.add(result);

while (res.moveToNext());


catch (Exception e)
e.printStackTrace();

Log.d(TAG,"here");
Collections.sort(processResults, new ArraySort());
/*Rearrange the Top 3 Best Match. Result with the same Parasite ID with the highest Match
remain while the other one will be remove from the list
By doing this ArrayList with Index from 0-2 is now the Top 3 Match with different parasite id
*/
for(int i = 0; i < processResults.size(); i++)
Log.d("Top3",processResults.get(i).getResult().toString());

int index = 0;
for(int i = 0; i < processResults.size()-1; i++)
ProcessResult result1 = processResults.get(i);
for(int y=i+1;y < (processResults.size()-1)-i;y++)
ProcessResult result2 = processResults.get(y);
Log.d("Top3",result1.getSucculentID()+" Compared to "+result2.getSucculentID());
if(result1.getSucculentID().equals(result2.getSucculentID()))
processResults.remove(i+1);



for(int i = 0; i < processResults.size(); i++)
Log.d("Top3","ID="+processResults.get(i).getSucculentID()+" Rate:"+processResults.get(i).getResult().toString());

return null;


@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
progressDialog.dismiss();

//tempo
Intent intent = new Intent(CameraActivity.this, Match.class);

intent.putExtra("top1",processResults.get(0).getSucculentID());
intent.putExtra("percentage1",processResults.get(0).getResult()+"");
Log.d("Top1","ID="+processResults.get(0).getSucculentID()+" Rate:"+processResults.get(0).getResult().toString());

intent.putExtra("top2",processResults.get(1).getSucculentID());
intent.putExtra("percentage2",processResults.get(1).getResult()+"");
Log.d("Top2","ID="+processResults.get(1).getSucculentID()+" Rate:"+processResults.get(1).getResult().toString());

intent.putExtra("top3",processResults.get(2).getSucculentID());
intent.putExtra("percentage3",processResults.get(2).getResult()+"");
Log.d("Top3","ID="+processResults.get(2).getSucculentID()+" Rate:"+processResults.get(2).getResult().toString());

intent.putExtra("from","ProcessImage");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

;
task.execute("");


public Bitmap getTakenImage()
//String path = getApplicationContext().getExternalFilesDir(null).toString()+"/pic.jpg";
Bitmap bmp = ((BitmapDrawable) imgTaken.getDrawable()).getBitmap();
return bmp;

@Override
public boolean onOptionsItemSelected(MenuItem item)
finish();
return true;




@Override
public void onClick(View view)
switch (view.getId())
case R.id.btnProcess:
Cursor res;
db = new DBController(this);

process();
break;
case R.id.btnBack:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
//finish();
break;
default:
break;



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
if (resultCode == RESULT_OK)
Bitmap bp = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");

new Utility(CameraActivity.this).SaveTemp(bp,""+1);
btnProcess.setEnabled(true);
imgTaken.setImageBitmap(bp);
else if (resultCode == RESULT_CANCELED)
// User cancelled the image capture
else
// Image capture failed, advise user




public int compareFeature(Bitmap bmp1, Bitmap bmp2)




LOGCAT



E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.geraldine.succulentidentifierapplication, PID: 3652
java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.geraldine.succulentidentifierapplication/com.example.geraldine.succulentidentifierapplication.CameraActivity: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at com.example.geraldine.succulentidentifierapplication.CameraActivity.onCreate(CameraActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6666)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6251) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 










share|improve this question
















public class CameraActivity extends AppCompatActivity implements View.OnClickListener



static 
System.loadLibrary("opencv_java3");
String TAG = "OpenCVLibrary";
if(!OpenCVLoader.initDebug())
Log.d(TAG,"OpenCv Not Successfully Loaded");
else
Log.d(TAG,"OpenCv Successfully Loaded");


private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
DBController db;
ImageProcessing imgproc;
Button btnProcess;
Cursor res;
ProgressDialog progressDialog;
ImageView imgTaken;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
// Objects.requireNonNull(getSupportActionBar()).setTitle("Camera");
OpenCVLoader.initDebug();
//Initialize View
imgTaken = findViewById(R.id.imgTaken);
btnProcess = findViewById(R.id.btnProcess);
btnProcess.setEnabled(false);
Button btnBack = findViewById(R.id.btnBack);
//Create a Bitmap of the Image captured using camera
//imgTaken.setImageBitmap(getTakenImage());
//Set OnClick Listener
btnBack.setOnClickListener(this);
btnProcess.setOnClickListener(this);



public void process()
final String TAG = "Image Processing";
progressDialog = new ProgressDialog(CameraActivity.this);

final ArrayList<ProcessResult> processResults = new ArrayList<>();
db = new DBController(this);
imgproc = new ImageProcessing();
AsyncTask<String,String,String> task = new AsyncTask<String, String, String>()
@Override
protected void onPreExecute()
super.onPreExecute();
//Processing Dialog

progressDialog.setMessage("Processing Image nPlease wait!...");
progressDialog.setCancelable(false);
progressDialog.show();



@Override
protected String doInBackground(String... strings)
/*Compute for the Match Percentage of the Image
compareFeature Method
First Params = Parasite Image
Second Params = Image Taken

Retrieve all Parasite Image in the Database
*/
try
res = db.getAllData("tbl_succulentsinfo");
Log.d(TAG, "" + res.getCount());

if (res.moveToFirst())
//String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.thesis.app.parafish/files/" + res.getString(2);
//Bitmap tmpbmp = BitmapFactory.decodeFile(file);
int rate = 0;

Log.d(TAG,rate+"");
do
Log.e(TAG, res.getString(0) + "/" + res.getString(1) + "/" + res.getString(2)+ "/" + res.getString(3)+ "/" + res.getString(4));
String imgpath = res.getString(3);
String[] newimgpath = imgpath.split("/");
String file = Environment.getExternalStorageDirectory().toString() + "/Android/data/com.example.geraldine.succulentidentifierapplication/files/" + newimgpath[1];
Bitmap tmpbmp = BitmapFactory.decodeFile(file);

ProcessResult result = new ProcessResult();

if(tmpbmp!=null &&getTakenImage()!=null)

rate = compareFeature(tmpbmp, getTakenImage());


Log.d(TAG, rate + "");
result.setSucculentID(res.getString(0));
result.setResult(rate);
processResults.add(result);

while (res.moveToNext());


catch (Exception e)
e.printStackTrace();

Log.d(TAG,"here");
Collections.sort(processResults, new ArraySort());
/*Rearrange the Top 3 Best Match. Result with the same Parasite ID with the highest Match
remain while the other one will be remove from the list
By doing this ArrayList with Index from 0-2 is now the Top 3 Match with different parasite id
*/
for(int i = 0; i < processResults.size(); i++)
Log.d("Top3",processResults.get(i).getResult().toString());

int index = 0;
for(int i = 0; i < processResults.size()-1; i++)
ProcessResult result1 = processResults.get(i);
for(int y=i+1;y < (processResults.size()-1)-i;y++)
ProcessResult result2 = processResults.get(y);
Log.d("Top3",result1.getSucculentID()+" Compared to "+result2.getSucculentID());
if(result1.getSucculentID().equals(result2.getSucculentID()))
processResults.remove(i+1);



for(int i = 0; i < processResults.size(); i++)
Log.d("Top3","ID="+processResults.get(i).getSucculentID()+" Rate:"+processResults.get(i).getResult().toString());

return null;


@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
progressDialog.dismiss();

//tempo
Intent intent = new Intent(CameraActivity.this, Match.class);

intent.putExtra("top1",processResults.get(0).getSucculentID());
intent.putExtra("percentage1",processResults.get(0).getResult()+"");
Log.d("Top1","ID="+processResults.get(0).getSucculentID()+" Rate:"+processResults.get(0).getResult().toString());

intent.putExtra("top2",processResults.get(1).getSucculentID());
intent.putExtra("percentage2",processResults.get(1).getResult()+"");
Log.d("Top2","ID="+processResults.get(1).getSucculentID()+" Rate:"+processResults.get(1).getResult().toString());

intent.putExtra("top3",processResults.get(2).getSucculentID());
intent.putExtra("percentage3",processResults.get(2).getResult()+"");
Log.d("Top3","ID="+processResults.get(2).getSucculentID()+" Rate:"+processResults.get(2).getResult().toString());

intent.putExtra("from","ProcessImage");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

;
task.execute("");


public Bitmap getTakenImage()
//String path = getApplicationContext().getExternalFilesDir(null).toString()+"/pic.jpg";
Bitmap bmp = ((BitmapDrawable) imgTaken.getDrawable()).getBitmap();
return bmp;

@Override
public boolean onOptionsItemSelected(MenuItem item)
finish();
return true;




@Override
public void onClick(View view)
switch (view.getId())
case R.id.btnProcess:
Cursor res;
db = new DBController(this);

process();
break;
case R.id.btnBack:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
//finish();
break;
default:
break;



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
if (resultCode == RESULT_OK)
Bitmap bp = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");

new Utility(CameraActivity.this).SaveTemp(bp,""+1);
btnProcess.setEnabled(true);
imgTaken.setImageBitmap(bp);
else if (resultCode == RESULT_CANCELED)
// User cancelled the image capture
else
// Image capture failed, advise user




public int compareFeature(Bitmap bmp1, Bitmap bmp2)




LOGCAT



E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.geraldine.succulentidentifierapplication, PID: 3652
java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.geraldine.succulentidentifierapplication/com.example.geraldine.succulentidentifierapplication.CameraActivity: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at com.example.geraldine.succulentidentifierapplication.CameraActivity.onCreate(CameraActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6666)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6251) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 







android opencv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 2:14







Geraldine Cruz

















asked Mar 7 at 14:19









Geraldine CruzGeraldine Cruz

11




11







  • 2





    Possible duplicate of What is a NullPointerException, and how do I fix it?

    – Tamir Abutbul
    Mar 7 at 14:21











  • i'm having a problem with this Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

    – Geraldine Cruz
    Mar 8 at 2:13












  • 2





    Possible duplicate of What is a NullPointerException, and how do I fix it?

    – Tamir Abutbul
    Mar 7 at 14:21











  • i'm having a problem with this Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

    – Geraldine Cruz
    Mar 8 at 2:13







2




2





Possible duplicate of What is a NullPointerException, and how do I fix it?

– Tamir Abutbul
Mar 7 at 14:21





Possible duplicate of What is a NullPointerException, and how do I fix it?

– Tamir Abutbul
Mar 7 at 14:21













i'm having a problem with this Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

– Geraldine Cruz
Mar 8 at 2:13





i'm having a problem with this Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

– Geraldine Cruz
Mar 8 at 2:13












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045992%2fe-androidruntime-fatal-exception-main-my-app-is-keep-on-closing-when-camera-b%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045992%2fe-androidruntime-fatal-exception-main-my-app-is-keep-on-closing-when-camera-b%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme