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

问题描述:

该应用程序短暂地打开白屏,几乎立即关闭。我会说时间是大约1-2秒。应用程序立即打开并关闭,不会崩溃

我试图卸载该应用,清除缓存等。

在调试应用程序,我没有看到任何脱颖而出。这是应用程序打开/关闭时涉及的堆栈跟踪。

我试着在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 

UPDATE:

最初开始使用这种类型的行为后我试图从一个片段转换PictureEditActivity到一个活动的应用程序。我修改了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 

     } 

    } 

} 
+2

你的'MainActivity'中有什么,特别是'onCreate()'?如果应用程序没有任何异常退出,那么有一些代码会退出,比如调用'finish()'。 – laalto 2014-09-30 13:11:21

+0

我上传了MainActivity。我尝试过放置一个断点,但似乎并没有受到影响。 – 2014-09-30 13:17:01

+1

有一些代码可以在'showPrimaryActivity()'中启动另一个活动,之后活动终止。后续问题:“NavigationActivity”中有什么? – laalto 2014-09-30 13:20:34

这是导致问题的代码。

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类中的一个不完整的构造。我纠正了构造函数,现在一切都很好。

+0

:(伤心........在这个问题中没有这样的东西......无论如何你现在把你的错误杀了它 – nobalG 2014-09-30 13:58:15

+0

我知道,直到我切换设备,我才收到错误信息。奇。 – 2014-09-30 14:06:41

if ((currentUser != null)) { 


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

从您的代码从onCreate()finish(),它使您的应用程序关闭.....

+0

我希望它是如此简单。我可以评论整个代码块,它仍然无法正常加载。在我开始处理问题之前,这段代码正常工作。 – 2014-09-30 13:24:14

+0

我正在谈论**完成()**您在** onCreate()中使用** ** ... – nobalG 2014-09-30 13:25:51

+0

我评论了所有完成()并且行为仍然存在。除非有一个活动的ParseUser,否则应该永远不会访问完成()块,在应用程序的开始部分不应该有任何活动的ParseUser,特别是在全新安装之后。 – 2014-09-30 13:32:07

可能是这个原因改变了每个意图对MainActivity.this并添加完成();到方法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);