应用程序立即打开和关闭,不会崩溃

时间:2014-09-30 13:06:21

标签: android

应用程序短暂打开白色屏幕,几乎立即关闭。我会说时间约为1-2秒。

我已尝试卸载应用,清除缓存等。

调试应用程序时,我没有看到任何突出的东西。这是app打开/关闭期间涉及的堆栈跟踪。

我尝试在MainActivity的OnCreate()中放置一个断点,它不会被击中。它似乎似乎没有进入MainActivity。

什么可能导致这种性质的东西?

09-30 09:02:42.225: E/WiFiOffloadingService(1189): setisWifiOntrue
    09-30 09:02:42.225: E/WiFiOffloadingService(1189): [W Offloading] getWifiOffloadingStart0
    09-30 09:02:42.225: E/WiFiOffloadingService(1189): setisWifiAPOn true
    09-30 09:02:42.395: E/jdwp(13206): Failed sending reply to debugger: Broken pipe
    09-30 09:02:42.835: E/BatteryObserver(1189): usb Uevent not necessary.
    09-30 09:02:44.525: E/[LGHome]NumberBadge.LGUnreadLgeEmailsBadge(1619): [LGUnreadLgeEmailsBadge.java:188:countUnreadItems()]Could not get cursor from provider for com.lge.email
    09-30 09:02:44.555: E/[LGHome]NumberBadge(1619): [LGNumberBadge.java:123:handleMessage()]MSG_RESPOND_RESULT_FROM_PROVIDER_FAILED
    09-30 09:02:47.755: E/BatteryObserver(1189): usb Uevent not necessary.
    09-30 09:02:47.945: E/LocSvc_afw(923): V/Entering int loc_inject_location(double, double, float) line 478 
    09-30 09:02:47.945: E/LocSvc_eng(923): I/===> int loc_eng_inject_location(loc_eng_data_s_type&, double, double, float) line 1941 
    09-30 09:02:47.945: E/LocSvc_afw(923): V/Exiting int loc_inject_location(double, double, float) line 502 0

更新

在尝试将PictureEditActivity从Fragment转换为Activity后,应用程序最初以此类行为开始。我修改了FeedActivity和PictureEditActivity中的代码以保持功能。

由于错误我在错误之前已恢复到之前的代码,但行为仍然存在。

分辨

在其他设备上测试应用后,导致错误。我将此错误追溯到我的应用程序的另一部分中的一行代码,涉及ParseDB并注册多个子类。

09-30 16:44:58.695: E/AndroidRuntime(23450): FATAL EXCEPTION: main
09-30 16:44:58.695: E/AndroidRuntime(23450): java.lang.RuntimeException: Unable to create application com.p.main.InitializeApplication: java.lang.IllegalArgumentException: Default constructor for class com.p.model.PUpload is not accessible.

AndroidManifest

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

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="21" />

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

    <uses-feature android:name="android.hardware.camera" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:name=".InitializeApplication"
        android:allowBackup="true"
        android:icon="@drawable/p_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SignUpActivity"
            android:label="@string/title_activity_sign_up"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
        </activity>
        <activity
            android:name=".NavigationActivity"
            android:label="@string/title_activity_navigation"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
        </activity>
        <activity
            android:name=".FeedActivity"
            android:label="@string/title_activity_feed"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
        </activity>
        <activity
            android:name=".UserActivity"
            android:label="@string/title_activity_user"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
        </activity>
        <activity
            android:name=".PictureEditActivity"
            android:label="@string/title_activity_picture_edit"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
        </activity>
    </application>

</manifest>

MainActivity

    public class MainActivity extends Activity implements OnClickListener {

    Button btnSignIn, btnSignUp;
    EditText etUsername, etPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnSignIn = (Button) findViewById(R.id.btnSignIn);
        btnSignIn.setOnClickListener(this);

        btnSignUp = (Button) findViewById(R.id.btnSignUp);
        btnSignUp.setOnClickListener(this);

        etUsername = (EditText) findViewById(R.id.editTextSignInUsername);
        etPassword = (EditText) findViewById(R.id.editTextSignInPassword);

        // Check if there is a currently logged in user
        // and they are linked to a Facebook account.
        final ParseUser currentUser = ParseUser.getCurrentUser();
        if ((currentUser != null)) {

            // you can add this line &&
            // ParseFacebookUtils.isLinked(currentUser)) to if statement
            // if you want to make sure the user is also linked to facebook
            // account
            // Go to the user info activity
            showPrimaryActivity();
            finish();
        }

    }

    @Override
    public void onResume() {
        super.onResume(); // Always call the superclass method first

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {
        case R.id.btnSignIn:

            String username = etUsername.getText().toString().toLowerCase()
                    .trim();
            String password = etPassword.getText().toString().toLowerCase()
                    .trim();

            try {
                if (username.isEmpty() || password.isEmpty()) {
                    if (username.isEmpty()) {
                        etUsername.setHintTextColor(getResources().getColor(
                                R.color.red));
                        etUsername.setHint("Enter Username");
                    }
                    if (password.isEmpty()) {
                        etPassword.setHintTextColor(getResources().getColor(
                                R.color.red));
                        etPassword.setHint("Enter Password");
                    }

                }
            } finally {
                if (!username.isEmpty() || !password.isEmpty()) {
                    ParseUser.logInInBackground(username, password,
                            new LogInCallback() {
                                public void done(ParseUser user,
                                        ParseException e) {
                                    if (user != null) {
                                        showPrimaryActivity();
                                        finish();
                                        // Hooray! The user is logged in.
                                    } else {

                                        etUsername.getText().clear();
                                        etUsername
                                                .setHintTextColor(getResources()
                                                        .getColor(R.color.red));
                                        etUsername.setHint("Invalid Username");

                                        etPassword.getText().clear();
                                        etPassword
                                                .setHintTextColor(getResources()
                                                        .getColor(R.color.red));
                                        etPassword.setHint("Invalid Password");
                                        Log.e("LOGIN FAILED",
                                                "FAILED TO LOG IN");
                                        // Signup failed. Look at the
                                        // ParseException to see what happened.
                                    }
                                }
                            });
                }

            }
            break;

        case R.id.btnSignUp:
            Intent intent1 = new Intent(this, SignUpActivity.class);
            startActivity(intent1);
            break;
        }

    }

    private void showPrimaryActivity() {
        Intent intent = new Intent(this, NavigationActivity.class);
        startActivity(intent);
    }

}

NavigationActivity

public class NavigationActivity extends FragmentActivity implements
        TabHost.OnTabChangeListener {

    private TabHost mTabHost;
    private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, TabInfo>();
    private TabInfo mLastTab = null;
    Context context;

    private class TabInfo {
        private String _tag;
        private int _labelId;
        private int _drawableId;
        @SuppressWarnings("rawtypes")
        private Class _class;
        private Bundle _args;
        private Fragment _fragment;

        @SuppressWarnings("rawtypes")
        TabInfo(int labelID, int drawableId, Class cl, Bundle args) {
            this._tag = "tab" + labelID;
            this._labelId = labelID;
            this._drawableId = drawableId;
            this._class = cl;
            this._args = args;
        }

        public int get_labelId() {
            return _labelId;
        }

        public int get_drawableId() {
            return _drawableId;
        }

        @SuppressWarnings("rawtypes")
        public Class get_class() {
            return _class;
        }

        public Fragment get_fragment() {
            return _fragment;
        }

        public String get_tag() {
            return _tag;
        }

    }



    class TabFactory implements TabContentFactory {

        private final Context mContext;

        /**
         * @param context
         */
        public TabFactory(Context context) {
            mContext = context;
        }

        /**
         * (non-Javadoc)
         *
         * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
         */
        public View createTabContent(String tag) {
            View v = new View(mContext);
            v.setMinimumWidth(0);
            v.setMinimumHeight(0);
            return v;
        }

    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ViewGroup vg = (ViewGroup) findViewById(R.id.main_root);

        context = this;

        // Step 2: Setup TabHost
        initialiseTabHost(savedInstanceState);
        if (savedInstanceState != null) {
            // set the tab as per the saved state
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
        }

    }

    @Override
    public void onResume() {
        super.onResume();

    }

    private void showLoginActivity() {
        Intent intent = new Intent(context, MainActivity.class);
        startActivity(intent);
    }

    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("tab", mTabHost.getCurrentTabTag()); // save the tab
        // selected
        super.onSaveInstanceState(outState);
    }

    /**
     * Step 2: Setup TabHost
     */
    private void initialiseTabHost(Bundle args) {
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup();
        mTabHost.getTabWidget().setDividerDrawable(null);

        addTab(R.string.lbl_title, R.drawable.ico_list, FeedActivity.class,
                args);
        addTab(R.string.lbl_user, R.drawable.ico_person, UserActivity.class,
                args);

        // Default to first tab
        mTabHost.setCurrentTabByTag("tab" + R.string.lbl_title);
        this.onTabChanged("tab" + R.string.lbl_title);

        mTabHost.setOnTabChangedListener(this);
    }

    private void addTab(int labelID, int drawableId, Class cl, Bundle args) {

        TabInfo tabInfo = null;
        tabInfo = new TabInfo(labelID, drawableId, cl, args);
        this.mapTabInfo.put(tabInfo.get_tag(), tabInfo);

        TabHost.TabSpec spec = mTabHost.newTabSpec(tabInfo._tag);

        View tabIndicator = LayoutInflater.from(this).inflate(
                R.layout.tab_indicator,
                (ViewGroup) findViewById(android.R.id.tabs), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(tabInfo.get_labelId());
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(tabInfo.get_drawableId());

        spec.setIndicator(tabIndicator);

        // Attach a Tab view factory to the spec
        spec.setContent(this.new TabFactory(this));
        String tag = spec.getTag();

        // Check to see if we already have a fragment for this tab, probably
        // from a previously saved state. If so, deactivate it, because our
        // initial state is that a tab isn't shown.
        tabInfo._fragment = this.getSupportFragmentManager().findFragmentByTag(
                tag);
        if (tabInfo._fragment != null && !tabInfo._fragment.isDetached()) {
            FragmentTransaction ft = this.getSupportFragmentManager()
                    .beginTransaction();
            ft.detach(tabInfo._fragment);
            ft.commit();
            this.getSupportFragmentManager().executePendingTransactions();
        }

        mTabHost.addTab(spec);
    }

    public void onTabChanged(String tag) {
        TabInfo newTab = this.mapTabInfo.get(tag);
        if (mLastTab != newTab) {
            FragmentTransaction ft = this.getSupportFragmentManager()
                    .beginTransaction();
            if (mLastTab != null) {
                if (mLastTab._fragment != null) {
                    ft.detach(mLastTab._fragment);
                }
            }
            if (newTab != null) {
                if (newTab.get_fragment() == null) {
                    newTab._fragment = Fragment.instantiate(this, newTab
                            .get_class().getName(), newTab._args);
                    ft.add(R.id.realtabcontent, newTab.get_fragment(),
                            newTab._tag);
                } else {
                    ft.attach(newTab.get_fragment());
                }
            }

            mLastTab = newTab;
            ft.commit();
            this.getSupportFragmentManager().executePendingTransactions();
        }
    }
}

FeedFragment

public class FeedActivity extends Fragment implements OnClickListener {

    ImageView m_ImageView;

    ImageButton btnCamera, btnGallery;
    private final String TAG_CAMERA_FRAGMENT = "camera_fragment";
    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    private Uri fileUri;
    public static final int MEDIA_TYPE_IMAGE = 1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.activity_feed, container, false);

        btnCamera = (ImageButton) view.findViewById(R.id.btn_Camera);
        btnCamera.setOnClickListener(this);
        btnGallery = (ImageButton) view.findViewById(R.id.btn_Gallery);
        btnGallery.setOnClickListener(this);

        return view;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {

        case R.id.btn_Camera:
            Log.e("CAMERA", "CAMERA BUTTON PRESSED");
            takePicture();
            break;

        case R.id.btn_Gallery:
            Log.e("Gallery", "GALLERY BUTTON PRESSED");
            break;

        }

    }

    public void takePicture() {

        // create Intent to take a picture and return control to the calling
        // application
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

        // start the image capture Intent
        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

            if (resultCode == getActivity().RESULT_OK) {
                Log.e("ONACTIVITYRESULT",
                        "-----------------RESULT_OK----------------");
                Bundle bundle = new Bundle();
                bundle.putParcelable("URI", fileUri);

                Fragment fragment = new PictureEditActivity();
                fragment.setArguments(bundle);

                // Intent intent = new Intent(getActivity(),
                // PictureEditActivity.class);
                // intent.putExtra("BUNDLE", bundle);
                // startActivity(intent);

                getFragmentManager()
                        .beginTransaction()
                        .replace(R.id.contentFragment, fragment,
                                TAG_CAMERA_FRAGMENT).commit();

                if (fileUri != null) {
                    Log.e("CAMERA", "Image saved to:\n" + fileUri);
                    Log.e("CAMERA", "Image path:\n" + fileUri.getPath());
                }

            } else if (resultCode == getActivity().RESULT_CANCELED) {
                Log.e("ONACTIVITYRESULT",
                        "-----------------RESULT_CANCELLED----------------");

            } else {

            }
        }

    }

    /** Create a file Uri for saving an image or video */
    private static Uri getOutputMediaFileUri(int type) {
        return Uri.fromFile(getOutputMediaFile(type));
    }

    /** Create a File for saving an image or video */
    private static File getOutputMediaFile(int type) {
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.

        File mediaStorageDir = new File(
                Environment
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "P");
        // This location works best if you want the created images to be shared
        // between applications and persist after your app has been uninstalled.

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("P", "failed to create directory");
                return null;
            }
        }

        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator
                    + "IMG_" + timeStamp + ".jpg");
        } else {
            return null;
        }

        return mediaFile;
    }
}

PictureEdit

    public class PictureEditActivity extends Fragment implements OnClickListener {

    ImageView m_ImageView;
    FrameLayout m_Layout;
    LinearLayout l_Layout, d_Layout;
    ImageButton btnBorder, btnSticker, btnEffect, btnAccept, btnMust1,
            btnMust2, btnBorderHome, btnStickerHome, btnDraw;

    ImageButton btnDrawColorRed, btnDrawColorOrange, btnDrawColorYellow,
            btnDrawColorGreen, btnDrawColorBlue, btnDrawColorIndigo,
            btnDrawColorViolet, btnDrawColorPink, btnDrawColorPurple,
            btnDrawColorBlack, btnDrawColorWhite, btnDrawColorBrown;

    HorizontalScrollView home_hScrollView, border_hScrollView,
            sticker_hScrollView, random_hView;

    Context context;

    CustomPaintView p_View;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.activity_picture_edit, container,
                false);

        p_View = new CustomPaintView(getActivity());

        m_Layout = (FrameLayout) view.findViewById(R.id.root_layout);
        l_Layout = (LinearLayout) view
                .findViewById(R.id.horizontalScrollbar_Layout);
        d_Layout = (LinearLayout) view
                .findViewById(R.id.linearLayoutDrawDetail);

        home_hScrollView = (HorizontalScrollView) view
                .findViewById(R.id.horizontalScrollViewHome);
        border_hScrollView = (HorizontalScrollView) view
                .findViewById(R.id.horizontalScrollViewBorder);
        sticker_hScrollView = (HorizontalScrollView) view
                .findViewById(R.id.horizontalScrollViewSticker);

        btnBorder = (ImageButton) view.findViewById(R.id.imageButtonBorder);
        btnBorder.setOnClickListener(this);

        btnSticker = (ImageButton) view.findViewById(R.id.imageButtonSticker);
        btnSticker.setOnClickListener(this);

        btnAccept = (ImageButton) view.findViewById(R.id.btn_Accept);
        btnAccept.setOnClickListener(this);

        btnMust1 = (ImageButton) view.findViewById(R.id.imageButton1);
        btnMust1.setOnClickListener(this);

        btnMust2 = (ImageButton) view.findViewById(R.id.imageButton2);
        btnMust2.setOnClickListener(this);

        btnDraw = (ImageButton) view.findViewById(R.id.imageButtonDraw);
        btnDraw.setOnClickListener(this);

        btnBorderHome = (ImageButton) view
                .findViewById(R.id.imageButtonBorderHome);
        btnBorderHome.setOnClickListener(this);

        btnStickerHome = (ImageButton) view
                .findViewById(R.id.imageButtonStickerHome);
        btnStickerHome.setOnClickListener(this);

        // COLOR BUTTONS

        btnDrawColorRed = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorRed);
        btnDrawColorRed.setOnClickListener(this);
        btnDrawColorOrange = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorOrange);
        btnDrawColorOrange.setOnClickListener(this);
        btnDrawColorYellow = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorYellow);
        btnDrawColorYellow.setOnClickListener(this);
        btnDrawColorGreen = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorGreen);
        btnDrawColorGreen.setOnClickListener(this);
        btnDrawColorBlue = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorBlue);
        btnDrawColorBlue.setOnClickListener(this);
        btnDrawColorIndigo = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorIndigo);
        btnDrawColorIndigo.setOnClickListener(this);
        btnDrawColorViolet = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorViolet);
        btnDrawColorViolet.setOnClickListener(this);

        btnDrawColorPink = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorPink);
        btnDrawColorPink.setOnClickListener(this);

        btnDrawColorPurple = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorPurple);
        btnDrawColorPurple.setOnClickListener(this);

        btnDrawColorBlack = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorBlack);
        btnDrawColorBlack.setOnClickListener(this);

        btnDrawColorWhite = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorWhite);
        btnDrawColorWhite.setOnClickListener(this);

        btnDrawColorBrown = (ImageButton) view
                .findViewById(R.id.imageButtonDrawColorBrown);
        btnDrawColorBrown.setOnClickListener(this);

        // Bundle extras = getIntent().getExtras();
        // Uri fileUri = extras.getParcelable("URI");
        // //m_ImageView = (ImageView) findViewById(R.id.imageViewEdit);
        // previewCapturedImage(fileUri);
        return view;

    }

    /*
     * Display image from a path to ImageView
     */
    private void previewCapturedImage(Uri fileUri) {
        try {
            // bimatp factory
            BitmapFactory.Options options = new BitmapFactory.Options();

            // downsizing image as it throws OutOfMemory Exception for larger
            // images
            options.inSampleSize = 2;

            Bitmap bitmap = BitmapFactory
                    .decodeFile(fileUri.getPath(), options);

            Matrix matrix = new Matrix();
            matrix.postRotate(90);
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                    bitmap.getHeight(), matrix, true);

            m_ImageView.setImageBitmap(bitmap);
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {

        case R.id.imageButtonBorder:
            // CustomImageView m_View = new CustomImageView(getActivity(),
            // R.drawable.p_logo);
            // m_Layout.addView(m_View);
            l_Layout.removeAllViews();
            l_Layout.addView(border_hScrollView);

            break;

        case R.id.imageButtonSticker:

            l_Layout.removeAllViews();
            l_Layout.addView(sticker_hScrollView);

            break;

        case R.id.btn_Accept:
            finalizeBitmap(m_Layout);
            Log.e("IMAGE SAVED", "IMAGE SAVED");
            break;

        case R.id.imageButton1:

            CustomImageView m_View = new CustomImageView(getActivity(),
                    R.drawable.must1);
            m_Layout.addView(m_View);

            break;

        case R.id.imageButton2:

            CustomImageView m_View1 = new CustomImageView(getActivity(),
                    R.drawable.must2);
            m_Layout.addView(m_View1);

            break;

        case R.id.imageButtonBorderHome:
            l_Layout.removeAllViews();
            l_Layout.addView(home_hScrollView);

            break;

        case R.id.imageButtonStickerHome:
            l_Layout.removeAllViews();
            l_Layout.addView(home_hScrollView);
            break;

        case R.id.imageButtonDraw:
            // CustomPaintView p_View = new CustomPaintView(getActivity());
            m_Layout.addView(p_View);
            l_Layout.removeAllViews();
            l_Layout.addView(d_Layout);

        case R.id.imageButtonDrawColorRed:
            p_View.setColor("#FF0000");

            break;
        case R.id.imageButtonDrawColorOrange:
            p_View.setColor("#FF3300");
            break;
        case R.id.imageButtonDrawColorYellow:
            p_View.setColor("#FFFF00");
            break;
        case R.id.imageButtonDrawColorGreen:
            p_View.setColor("#009900");
            break;
        case R.id.imageButtonDrawColorBlue:
            p_View.setColor("#0000FF");
            break;
        case R.id.imageButtonDrawColorIndigo:
            p_View.setColor("#9966FF");
            break;
        case R.id.imageButtonDrawColorViolet:
            p_View.setColor("#660066");
            break;
        case R.id.imageButtonDrawColorPink:
            p_View.setColor("#FF0066");
            break;
        case R.id.imageButtonDrawColorPurple:
            p_View.setColor("#333399");
            break;
        case R.id.imageButtonDrawColorWhite:
            p_View.setColor("#FFFFFF");
            break;
        case R.id.imageButtonDrawColorBlack:
            p_View.setColor("#000000");
            break;
        case R.id.imageButtonDrawColorBrown:
            p_View.setColor("#663300");
            break;

        }

    }

    public void finalizeBitmap(View view) {
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache(true);
        Bitmap bitmap = view.getDrawingCache();
        saveToInternalStorage(bitmap);

    }

    private void saveToInternalStorage(Bitmap bitmapImage) {
        ContextWrapper cw = new ContextWrapper(getActivity());
        File root = new File(Environment.getExternalStorageDirectory()
                + File.separator + "Pictures" + File.separator + "P"
                + File.separator);

        if (!root.exists()) {
            root.mkdirs();
            Log.e("ROOT", "DIRECTORY DOES NOT EXIST");
        } else {
            Log.e("ROOT", "DIRECTORY EXISTS");
            File sdImageMainDirectory = new File(root, "p_"
                    + (System.currentTimeMillis() / 1000L) + ".png");

            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(sdImageMainDirectory);

                bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
                fos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            intent.setData(Uri.fromFile(sdImageMainDirectory));
            getActivity().sendBroadcast(intent);
            Log.e("DIRECTORY", "" + sdImageMainDirectory.getAbsolutePath());
            getActivity().getSupportFragmentManager().beginTransaction()
                    .remove(this).commit();

            // change activity to something to share the picture

        }

    }

}

3 个答案:

答案 0 :(得分:2)

if ((currentUser != null)) {


            showPrimaryActivity();
            finish();         //remove this
        }

finish()中删除代码中的onCreate(),它会让您的应用关闭.....

答案 1 :(得分:0)

可能是因为将每个意图更改为MainActivity.this并添加finish();方法showPrimaryActivity()确保完成后不打开应用程序只需打开

 private void showPrimaryActivity() {
        Intent intent = new Intent(MainActivity.this, NavigationActivity.class);
        startActivity(intent);
      finish();
         }    

    Intent intent1 = new Intent(MainActivity.this, SignUpActivity.class);
            startActivity(intent1);

答案 2 :(得分:0)

以下是导致问题的代码。

public class InitializeApplication extends Application {

    static final String TAG = "MyApp";

    @Override
    public void onCreate() {
        super.onCreate();

        ParseObject.registerSubclass(Receipt.class);
        ParseObject.registerSubclass(PUpload.class);  ///<<< ISSUE

        Parse.initialize(this, "XXXXXXXXXXXXXXXXXXXXXXXXXX",
                "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
}

在注释掉该行代码之后,不会再抛出任何错误。

FULL FIX

错误是由于我的ParseObject PUpload类中的构造函数不完整所致。我纠正了构造函数,现在一切都很顺利。