我尝试像下面这样运行我的代码,但是当我点击摄像机内部片段的捕获按钮时,我遇到了异常。
我的项目建立在导航抽屉上,它采用片段和内部片段ChangeMeterForm
我添加了另一个片段ServiceInfo
,其中包含有关客户的详细信息。
但是当我点击捕获按钮时,我在serviceInfo
片段中出现了异常。我尝试了很多解决方案,但每次我都遇到同样的错误
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.replace_meter_form, container, false);
try
{
context = getActivity();
serviceItems = new ArrayList<ServiceObj>();
// Ticket Session Manager
session = new SessionManager(context);
dbObject = new SQLiteDB(context);
Ticket t_info = session.getTicketInfo();
final String ticketSeqID = t_info.getSeqID();
final int ticket_index_id = t_info.getId();
final String serviceId = t_info.getServiceId();
session.setTicketID(ticket_index_id);
// get user ticket and employee id's
final String system_user = t_info.getUserInput();
final String empID = session.getEmployeeDetails().getEmpID();
ListValueHandler handler = new ListValueHandler(context, dbObject);
getServiceMeters task = new getServiceMeters();
task.execute(serviceId);
// get the service information frame
try
{
Bundle params = new Bundle();
params.putString("serviceId", session.getTicketInfo().getServiceId());
// initlize fragment object
serviceInfo serInfoFrag = new serviceInfo();
serInfoFrag.setArguments(params);
//calling manager
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// excute and show fragment
transaction.add(R.id.serviceDetails_replaceMeter, serInfoFrag).commit();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private Uri captureImage(String name)
{
try
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE, name);
//Log.d("Directory ", fileUri.getPath());
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return fileUri;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if the result is capturing Image
//delete image if exist
//insert new image
IMAGE newImage = new IMAGE();
dbObject.deleteImage(session.getImageName(), session.getTicketInfo().getGroupType(),"1",session.getTicketInfo().getServiceId());
newImage.setServiceId(session.getTicketInfo().getServiceId());
newImage.setImageName(session.getImageName());
newImage.setImagePath(CONSTANTS.getImagePath(IMAGE_DIRECTORY_NAME, session.getTicketInfo().getGroupType()) + session.getImageName() + ".jpg");
newImage.setActionType("1");
newImage.setGroupType(session.getTicketInfo().getGroupType());
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(context,"Image Captured ",Toast.LENGTH_LONG).show();
// successfully captured the image
// display it in image view
try
{
previewCapturedImage();
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (resultCode == Activity.RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(context,context.getResources().getText(R.string.cancel_capture_camera_lbl),Toast.LENGTH_SHORT).show();
} else {
// failed to capture image
Toast.makeText(context, context.getText(R.string.failed_capture_camera_lbl), Toast.LENGTH_SHORT).show();
}
dbObject.insertNewImage(newImage);
}
}
private void previewCapturedImage() {
try
{
Toast.makeText(context,"Show Images",Toast.LENGTH_LONG).show();
String newMeterNo = newMeterID.getText().toString().trim();
final String ticketIndex = session.getTicketInfo().getServiceId() + "_" + newMeterNo;
String path1 = CONSTANTS.getImagePath("ReplacedMeters", session.getTicketInfo().getGroupType()) + ticketIndex + "_1.jpg";
String path2 = CONSTANTS.getImagePath("ReplacedMeters", session.getTicketInfo().getGroupType()) + ticketIndex + "_2.jpg";
String path3 = CONSTANTS.getImagePath("ReplacedMeters", session.getTicketInfo().getGroupType()) + ticketIndex + "_3.jpg";
String path4 = CONSTANTS.getImagePath("ReplacedMeters", session.getTicketInfo().getGroupType()) + ticketIndex + "_4.jpg";
String path5 = CONSTANTS.getImagePath("ReplacedMeters", session.getTicketInfo().getGroupType()) + ticketIndex + "_5.jpg";
Toast.makeText(context,"Path 1 "+path1,Toast.LENGTH_LONG).show();
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
// downsizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 8;
File pic = new File(path1);
if (pic.exists()) {
final Bitmap bitmap1 = BitmapFactory.decodeFile(path1,
options);
imageButton1.setImageBitmap(bitmap1);
}
pic = new File(path2);
if (pic.exists()) {
final Bitmap bitmap2 = BitmapFactory.decodeFile(path2,
options);
imageButton2.setImageBitmap(bitmap2);
}
pic = new File(path3);
if (pic.exists()) {
final Bitmap bitmap3 = BitmapFactory.decodeFile(path3,
options);
imageButton3.setImageBitmap(bitmap3);
}
pic = new File(path5);
if (pic.exists()) {
final Bitmap bitmap5 = BitmapFactory.decodeFile(path5,
options);
idImageBtn.setImageBitmap(bitmap5);
}
pic = new File(path4);
if (pic.exists()) {
final Bitmap bitmap5 = BitmapFactory.decodeFile(path4,
options);
imageButton4.setImageBitmap(bitmap5);
}
} catch (Exception e) {
e.printStackTrace();
//Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
异常
STACK_TRACE=java.lang.RuntimeException: Unable to start activity ComponentInfo{cpm.jdeco.metersapp/com.jdeco.metersapp.activity.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f0f0148 (cpm.jdeco.metersapp:id/serviceDetails_replaceMeter) for fragment serviceInfo{35c646f #3 id=0x7f0f0148}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3133)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3243)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5180)
at android.app.ActivityThread.access$1100(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6914)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0f0148 (cpm.jdeco.metersapp:id/serviceDetails_replaceMeter) for fragment serviceInfo{35c646f #3 id=0x7f0f0148}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1264)
at android.app.Activity.performStart(Activity.java:6646)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3096)