Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android java.lang.RuntimeException:无法恢复活动(设置从相机捕获的图像时)_Android_Exception_Android Activity_Android Tabhost_Device - Fatal编程技术网

Android java.lang.RuntimeException:无法恢复活动(设置从相机捕获的图像时)

Android java.lang.RuntimeException:无法恢复活动(设置从相机捕获的图像时),android,exception,android-activity,android-tabhost,device,Android,Exception,Android Activity,Android Tabhost,Device,我正在尝试在我的应用程序中使用camera类。我只想单击一张图片并在imageview上设置,然后将其发布到某个url上。在url上发布工作正常,但在单击任何图片并从导航到摄像头应用程序的位置恢复到同一活动时,有时会出现问题。它在HTC wildfire(2.2版)上运行良好,但有时会出现异常(故障概率1/25),但当我在Sony xperia miro或samsung tab(4.0版)上测试它时,会多次出现相同的异常(故障概率20/25)。我不明白问题存在的地方,因为有时应用程序运行平稳,毫

我正在尝试在我的应用程序中使用camera类。我只想单击一张图片并在imageview上设置,然后将其发布到某个url上。在url上发布工作正常,但在单击任何图片并从导航到摄像头应用程序的位置恢复到同一活动时,有时会出现问题。它在HTC wildfire(2.2版)上运行良好,但有时会出现异常(故障概率1/25),但当我在Sony xperia miro或samsung tab(4.0版)上测试它时,会多次出现相同的异常(故障概率20/25)。我不明白问题存在的地方,因为有时应用程序运行平稳,毫无例外,但在4.0或更高版本中,它会强制关闭很多次,但有时在它上运行良好

异常为:
java.lang.RuntimeException:无法恢复活动{fable.eventippo/fable.eventippo.EventsIppoPaymentActivity}:java.lang.RuntimeException:未能传递结果ResultInfo{who=tabHome,请求=1,结果=1,数据=Intent{dat=content://media/external/images/media/17271 }}活动{fable.eventippo/fable.eventippo.eventsippaymentactivity}:java.lang.ClassCastException:fable.eventippo.Home不能强制转换为fable.eventippo.AddEvent

这里给出了完整的代码

按一下按钮

browse = (Button) findViewById(R.id.browse);
browse.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        final CharSequence[] items = { "Camera", "Gallery" };
        AlertDialog.Builder builder = new AlertDialog.Builder(
                getParent());
        builder.setTitle("Browse From");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (items[item] == "Camera") {
                    PackageManager pm = getPackageManager();

                    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
                        Intent i = new Intent(
                                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                        i.putExtra(MediaStore.EXTRA_OUTPUT,
                                MyFileContentProviders.CONTENT_URI);

                        getParent().startActivityForResult(i,
                                CAMERA_REQUEST);

                    } else {

                        Toast.makeText(getParent(),
                                "Camera is not available",
                                Toast.LENGTH_LONG).show();

                    }
                } else if (items[item] == "Gallery") {
                    try {

                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction(Intent.ACTION_GET_CONTENT);
                        getParent().startActivityForResult(
                                Intent.createChooser(intent,
                                        "Select Picture"),         PICK_IMAGE);
                    } catch (Exception e) {
                        Toast.makeText(getParent(), e.getMessage(),
                                Toast.LENGTH_LONG).show();
                        Log.e(e.getClass().getName(), e.getMessage(), e);
                    }

                }
            }

        });
        AlertDialog alert = builder.create();
        alert.show();

    }
});
关于活动结果:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

Bundle bn = data.getExtras();
switch (requestCode) {
case PICK_IMAGE:
    if (resultCode == Activity.RESULT_OK) {
        Uri selectedImageUri = data.getData();
        String filepath = null;

        try {
            // OI FILE Manager
            String filemanagerstring = selectedImageUri.getPath();
            // MEDIA GALLERY
            String selectedImagePath = getPath(selectedImageUri);
            // logo.setImageURI(selectedImageUri);
            if (selectedImagePath != null) {
                filepath = selectedImagePath;
            } else if (filemanagerstring != null) {
                filepath = filemanagerstring;
            } else {
                Toast.makeText(getApplicationContext(), "Unknown path",
                        Toast.LENGTH_LONG).show();
                Log.e("Bitmap", "Unknown path");
            }
            if (filepath != null) {
                // /upload.setText(filepath);
                decodeFile(filepath);
            } else {
                // filePath = null;
                bitmap = null;
            }
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "Internal error",
                    Toast.LENGTH_LONG).show();
            Log.e(e.getClass().getName(), e.getMessage(), e);
        }
    }
    break;
case CAMERA_REQUEST:
    if (resultCode == Activity.RESULT_OK) {

        File out = new File(getFilesDir(), "newImage.jpg");

        if (!out.exists()) {

            Toast.makeText(getBaseContext(),

            "Error while capturing image", Toast.LENGTH_LONG)

            .show();

            return;

        }

        String filepath = out.getAbsolutePath().toString();
        decodeFile(filepath);

    }
    break;
default:
}
下图显示了完全异常

Activity EventipPaymentActivity

公共类事件SIPPopaymentActivity扩展了TabActivity{

TabWidget mTabWidget;
TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);


  setTabs() ;
  } 
private void setTabs()
    {
       addTab("Home", R.drawable.home_icon, TabGroup1.class);
       addTab("Search", R.drawable.search_icon, TabGroup2.class);
       addTab("Add Event", R.drawable.addevent_icon, TabGroup3.class);
       addTab("Support", R.drawable.support_icon, TabGroup4.class);
    }

private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(),        false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
}
TabWidget-mTabWidget;
TabHost-TabHost;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs();
} 
私有void setTabs()
{
addTab(“Home”,R.drawable.Home_图标,TabGroup1.class);
addTab(“搜索”,R.drawable.Search_图标,TabGroup2.class);
addTab(“添加事件”,R.drawable.addevent_图标,TabGroup3.class);
addTab(“Support”,R.drawable.Support_图标,TabGroup4.class);
}
私有void addTab(字符串labelId,int-drawableId,c类)
{
TabHost TabHost=getTabHost();
意向=新意向(本,c);
TabHost.TabSpec spec=TabHost.newTabSpec(“tab”+labelId);
查看tabIndicator=LayoutInflater.from(this).充气(R.layout.tab_indicator,getTabWidget(),false);
TextView title=(TextView)tabIndicator.findViewById(R.id.title);
标题:setText(labelId);
ImageView图标=(ImageView)选项卡indicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
规格设置指示器(tabIndicator);
规格设置内容(意图);
tabHost.addTab(spec);
}

}

问题似乎出在“fable.eventipo.Home无法转换为fable.eventipo.AddEvent”中。是的。但不知道为什么它不起作用。你能展示你的活动吗code@IftikarUrrhmanKhan加上。请喝一杯look@VarunVishnoi在您的logcat中向下滚动,您可以找到导致此问题的行no,如果您可以将完整的logcat粘贴到此处