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)
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
add a comment |
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
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
add a comment |
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
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
android opencv
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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