草庐IT

android - 运行时异常无法启动 Activity

coder 2023-12-26 原文

我在 android 中制作了一个应用程序并且它工作正常但是当我将我的应用程序转移到我的主应用程序时它开始显示错误从那时起包名称与我以前的应用程序相同那么这也是我的错误得到。我关注了很多问题,但无法找到任何解决方案。

 FATAL EXCEPTION: main
                                              Process: unnion.neelay.beatbox, PID: 12739
                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{unnion.neelay.beatbox/unnion.neelay.beatbox.ringdroid.RingdroidSelectActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
                                                                       at android.app.ActivityThread.access$900(ActivityThread.java:153)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:148)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5441)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
                                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                       at unnion.neelay.beatbox.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:123)
                                                                       at android.app.Activity.performCreate(Activity.java:6303)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
                                                                       at android.app.ActivityThread.access$900(ActivityThread.java:153) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                       at android.os.Looper.loop(Looper.java:148) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5441) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) 

它显示空点异常,但在未添加到主应用程序时它工作正常。 ringdroid 选择 Activity

public class RingdroidSelectActivity
    extends ListActivity
    implements LoaderManager.LoaderCallbacks<Cursor> {
private SearchView mFilter;
private SimpleCursorAdapter mAdapter;
private boolean mWasGetContentIntent;
private boolean mShowAll;

private Cursor mExternalCursor;

// Result codes
private static final int EXT_STORAGE_PERMISSION_REQ_CODE = 2;
private static final int WRITE_EXTERNAL_STORAGE = 4;
private static final int READ_PHONE_STATE = 3;
private static final int WRITE_SETTINGS = 3;
private static final int CHANGE_CONFIGURATION = 1;
private static final int MODIFY_AUDIO_SETTINGS = 5;
private static final int INTERNET = 6;
private static final int REQUEST_CODE_EDIT = 1;
private static final int REQUEST_CODE_CHOOSE_CONTACT = 2;

// Context menu
private static final int CMD_EDIT = 4;
private static final int CMD_DELETE = 5;
private static final int CMD_SET_AS_DEFAULT = 6;
private static final int CMD_SET_AS_CONTACT = 7;


public RingdroidSelectActivity() {
}

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    checkReadStoragePermission();


    mShowAll = false;

    String status = Environment.getExternalStorageState();
    if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        showFinalAlert(getResources().getText(R.string.sdcard_readonly));
        return;
    }
    if (status.equals(Environment.MEDIA_SHARED)) {
        showFinalAlert(getResources().getText(R.string.sdcard_shared));
        return;
    }
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        showFinalAlert(getResources().getText(R.string.no_sdcard));
        return;
    }

    Intent intent = getIntent();
    mWasGetContentIntent = intent.getAction().equals(
            Intent.ACTION_GET_CONTENT);

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.media_select);
    getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    getActionBar().setDisplayShowTitleEnabled(false);
    try {
        mAdapter = new SimpleCursorAdapter(
                this,
                // Use a template that displays a text view
                R.layout.media_select_row,
                null,
                // Map from database columns...
                new String[]{
                        MediaStore.Audio.Media.ARTIST,

                        MediaStore.Audio.Media.TITLE,
                        MediaStore.Audio.Media._ID,
                        MediaStore.Audio.Media._ID},
                // To widget ids in the row layout...
                new int[]{
                        R.id.row_artist,

                        R.id.row_title,
                        R.id.row_icon,
                        R.id.row_options_button},
                0);

        setListAdapter(mAdapter);


        // Normal click - open the editor
        getListView().setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent,
                                    View view,
                                    int position,
                                    long id) {
                startRingdroidEditor();
            }
        });


        mExternalCursor = null;

        getLoaderManager().initLoader(EXTERNAL_CURSOR_ID, null, this);

    } catch (SecurityException e) {
        // No permission to retrieve audio?
        Log.e("Ringdroid", e.toString());

        // TODO error 1
    } catch (IllegalArgumentException e) {
        // No permission to retrieve audio?
        Log.e("Ringdroid", e.toString());

        // TODO error 2
    }

    mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (view.getId() == R.id.row_options_button) {
                // Get the arrow ImageView and set the onClickListener to open the context menu.
                ImageView iv = (ImageView) view;
                iv.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        openContextMenu(v);
                    }
                });
                return true;
            } else if (view.getId() == R.id.row_icon) {
                setSoundIconFromCursor((ImageView) view, cursor);
                return true;
            }

            return false;
        }
    });

    // Long-press opens a context menu
    registerForContextMenu(getListView());

}

private void setSoundIconFromCursor(ImageView view, Cursor cursor) {

    if (0 != cursor.getInt(cursor.getColumnIndexOrThrow(
            MediaStore.Audio.Media.IS_MUSIC))) {
        view.setImageResource(R.drawable.type_music);
        ((View) view.getParent()).setBackgroundColor(
                getResources().getColor(R.color.type_bkgnd_music));
    }

    String filename = cursor.getString(cursor.getColumnIndexOrThrow(
            MediaStore.Audio.Media.DATA));

}

/**
 * Called with an Activity we started with an Intent returns.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode,
                                Intent dataIntent) {
    if (requestCode != REQUEST_CODE_EDIT) {
        return;
    }

    if (resultCode != RESULT_OK) {
        return;
    }

    setResult(RESULT_OK, dataIntent);
    //finish();  // TODO(nfaralli): why would we want to quit the app here?
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.select_options, menu);

    mFilter = (SearchView) menu.findItem(R.id.action_search_filter).getActionView();
    if (mFilter != null) {
        mFilter.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            public boolean onQueryTextChange(String newText) {
                refreshListView();
                return true;
            }

            public boolean onQueryTextSubmit(String query) {
                refreshListView();
                return true;
            }
        });
    }

    return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    menu.findItem(R.id.action_record).setVisible(true);
    // TODO(nfaralli): do we really need a "Show all audio" item now?
    menu.findItem(R.id.action_show_all_audio).setVisible(true);
    menu.findItem(R.id.action_show_all_audio).setEnabled(!mShowAll);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        case R.id.action_record:
            onRecord();
            return true;
        case R.id.action_show_all_audio:
            mShowAll = true;
            refreshListView();
            return true;
        default:
            return false;
    }
}

@Override
public void onCreateContextMenu(ContextMenu menu,
                                View v,
                                ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    Cursor c = mAdapter.getCursor();
    String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));

    menu.setHeaderTitle(title);

    menu.add(0, CMD_EDIT, 0, R.string.context_menu_edit);
    menu.add(0, CMD_DELETE, 0, R.string.context_menu_delete);

    // Add items to the context menu item based on file type
    if (0 != c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_RINGTONE))) {
        menu.add(0, CMD_SET_AS_DEFAULT, 0, R.string.context_menu_default_ringtone);
        menu.add(0, CMD_SET_AS_CONTACT, 0, R.string.context_menu_contact);
    } else if (0 != c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_NOTIFICATION))) {
        menu.add(0, CMD_SET_AS_DEFAULT, 0, R.string.context_menu_default_notification);
    }
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case CMD_EDIT:
            startRingdroidEditor();
            return true;
        case CMD_DELETE:
            confirmDelete();
            return true;
        case CMD_SET_AS_DEFAULT:
            setAsDefaultRingtoneOrNotification();
            return true;
        case CMD_SET_AS_CONTACT:
            return chooseContactForRingtone(item);
        default:
            return super.onContextItemSelected(item);
    }
}

private void setAsDefaultRingtoneOrNotification() {
    Cursor c = mAdapter.getCursor();

    // If the item is a ringtone then set the default ringtone,
    // otherwise it has to be a notification so set the default notification sound
    if (0 != c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_RINGTONE))) {
        RingtoneManager.setActualDefaultRingtoneUri(
                RingdroidSelectActivity.this,
                RingtoneManager.TYPE_RINGTONE,
                getUri());
        Toast.makeText(
                RingdroidSelectActivity.this,
                R.string.default_ringtone_success_message,
                Toast.LENGTH_SHORT)
                .show();
    } else {
        RingtoneManager.setActualDefaultRingtoneUri(
                RingdroidSelectActivity.this,
                RingtoneManager.TYPE_NOTIFICATION,
                getUri());
        Toast.makeText(
                RingdroidSelectActivity.this,
                R.string.default_notification_success_message,
                Toast.LENGTH_SHORT)
                .show();
    }
}

private int getUriIndex(Cursor c) {
    int uriIndex;
    String[] columnNames = {
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI.toString(),
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString()
    };

    for (String columnName : Arrays.asList(columnNames)) {
        uriIndex = c.getColumnIndex(columnName);
        if (uriIndex >= 0) {
            return uriIndex;
        }
        // On some phones and/or Android versions, the column name includes the double quotes.
        uriIndex = c.getColumnIndex("\"" + columnName + "\"");
        if (uriIndex >= 0) {
            return uriIndex;
        }
    }
    return -1;
}

private Uri getUri() {
    //Get the uri of the item that is in the row
    Cursor c = mAdapter.getCursor();
    int uriIndex = getUriIndex(c);
    if (uriIndex == -1) {
        return null;
    }
    String itemUri = c.getString(uriIndex) + "/" +
            c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
    return (Uri.parse(itemUri));
}

private boolean chooseContactForRingtone(MenuItem item) {
    try {
        //Go to the choose contact activity
        Intent intent = new Intent(Intent.ACTION_EDIT, getUri());
        intent.setClassName(
                "unnion.neelay.beatbox.ringdroid",
                "unnion.neelay.beatbox.ringdroid.ChooseContactActivity");
        startActivityForResult(intent, REQUEST_CODE_CHOOSE_CONTACT);
    } catch (Exception e) {
        Log.e("Ringdroid", "Couldn't open Choose Contact window");
    }
    return true;
}

private void confirmDelete() {
    // See if the selected list item was created by Ringdroid to
    // determine which alert message to show
    Cursor c = mAdapter.getCursor();
    String artist = c.getString(c.getColumnIndexOrThrow(
            MediaStore.Audio.Media.ARTIST));
    CharSequence ringdroidArtist =
            getResources().getText(R.string.artist_name);

    CharSequence message;
    if (artist.equals(ringdroidArtist)) {
        message = getResources().getText(
                R.string.confirm_delete_ringdroid);
    } else {
        message = getResources().getText(
                R.string.confirm_delete_non_ringdroid);
    }

    CharSequence title;
    if (0 != c.getInt(c.getColumnIndexOrThrow(
            MediaStore.Audio.Media.IS_RINGTONE))) {
        title = getResources().getText(R.string.delete_ringtone);
    } else if (0 != c.getInt(c.getColumnIndexOrThrow(
            MediaStore.Audio.Media.IS_ALARM))) {
        title = getResources().getText(R.string.delete_alarm);
    } else if (0 != c.getInt(c.getColumnIndexOrThrow(
            MediaStore.Audio.Media.IS_NOTIFICATION))) {
        title = getResources().getText(R.string.delete_notification);
    } else if (0 != c.getInt(c.getColumnIndexOrThrow(
            MediaStore.Audio.Media.IS_MUSIC))) {
        title = getResources().getText(R.string.delete_music);
    } else {
        title = getResources().getText(R.string.delete_audio);
    }

    new AlertDialog.Builder(RingdroidSelectActivity.this)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(
                    R.string.delete_ok_button,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                            int whichButton) {
                            onDelete();
                        }
                    })
            .setNegativeButton(
                    R.string.delete_cancel_button,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                            int whichButton) {
                        }
                    })
            .setCancelable(true)
            .show();
}

private void onDelete() {
    Cursor c = mAdapter.getCursor();
    int dataIndex = c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
    String filename = c.getString(dataIndex);

    int uriIndex = getUriIndex(c);
    if (uriIndex == -1) {
        showFinalAlert(getResources().getText(R.string.delete_failed));
        return;
    }

    if (!new File(filename).delete()) {
        showFinalAlert(getResources().getText(R.string.delete_failed));
    }

    String itemUri = c.getString(uriIndex) + "/" +
            c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
    getContentResolver().delete(Uri.parse(itemUri), null, null);
}

private void showFinalAlert(CharSequence message) {
    new AlertDialog.Builder(RingdroidSelectActivity.this)
            .setTitle(getResources().getText(R.string.alert_title_failure))
            .setMessage(message)
            .setPositiveButton(
                    R.string.alert_ok_button,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                            int whichButton) {
                            finish();
                        }
                    })
            .setCancelable(false)
            .show();
}

private void onRecord() {
    try {
        Intent intent = new Intent(Intent.ACTION_EDIT, Uri.parse("record"));
        intent.putExtra("was_get_content_intent", mWasGetContentIntent);
        intent.setClassName("unnion.neelay.mediaplayer.ringdroid", "unnion.neelay.mediaplayer.ringdroid.RingdroidEditActivity");
        startActivityForResult(intent, REQUEST_CODE_EDIT);
    } catch (Exception e) {
        Log.e("Ringdroid", "Couldn't start editor");
    }
}

private void startRingdroidEditor() {
    Cursor c = mAdapter.getCursor();
    int dataIndex = c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
    String filename = c.getString(dataIndex);
    try {
        Intent intent = new Intent(Intent.ACTION_EDIT, Uri.parse(filename));
        intent.putExtra("was_get_content_intent", mWasGetContentIntent);
        intent.setClassName("unnion.neelay.mediaplayer.ringdroid", "unnion.neelay.mediaplayer.ringdroid.RingdroidEditActivity");
        startActivityForResult(intent, REQUEST_CODE_EDIT);
    } catch (Exception e) {
        Log.e("Ringdroid", "Couldn't start editor");
    }
}

private void refreshListView() {

    mExternalCursor = null;
    Bundle args = new Bundle();
    args.putString("filter", mFilter.getQuery().toString());
    getLoaderManager().restartLoader(EXTERNAL_CURSOR_ID, args, this);
}


private static final String[] EXTERNAL_COLUMNS = new String[]{
        MediaStore.Audio.Media._ID,
        MediaStore.Audio.Media.DATA,
        MediaStore.Audio.Media.TITLE,
        MediaStore.Audio.Media.ARTIST,
        MediaStore.Audio.Media.ALBUM,
        MediaStore.Audio.Media.IS_RINGTONE,
        MediaStore.Audio.Media.IS_ALARM,
        MediaStore.Audio.Media.IS_NOTIFICATION,
        MediaStore.Audio.Media.IS_MUSIC,
        "\"" + MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "\""
};

private static final int EXTERNAL_CURSOR_ID = 1;

/* Implementation of LoaderCallbacks.onCreateLoader */
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    ArrayList<String> selectionArgsList = new ArrayList<String>();
    String selection;
    Uri baseUri;
    String[] projection;

    switch (id) {

        case EXTERNAL_CURSOR_ID:
            baseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            projection = EXTERNAL_COLUMNS;
            break;
        default:
            return null;
    }

    if (mShowAll) {
        selection = "(_DATA LIKE ?)";
        selectionArgsList.add("%");
    } else {
        selection = "(";
        for (String extension : SoundFile.getSupportedExtensions()) {
            selectionArgsList.add("%." + extension);
            if (selection.length() > 1) {
                selection += " OR ";
            }
            selection += "(_DATA LIKE ?)";
        }
        selection += ")";

        selection = "(" + selection + ") AND (_DATA NOT LIKE ?)";
        selectionArgsList.add("%espeak-data/scratch%");
    }

    String filter = args != null ? args.getString("filter") : null;
    if (filter != null && filter.length() > 0) {
        filter = "%" + filter + "%";
        selection =
                "(" + selection + " AND " +
                        "((TITLE LIKE ?) OR (ARTIST LIKE ?) OR (ALBUM LIKE ?)))";
        selectionArgsList.add(filter);
        selectionArgsList.add(filter);
        selectionArgsList.add(filter);
    }

    String[] selectionArgs =
            selectionArgsList.toArray(new String[selectionArgsList.size()]);
    return new CursorLoader(
            this,
            baseUri,
            projection,
            selection,
            selectionArgs,
            MediaStore.Audio.Media.DEFAULT_SORT_ORDER
    );
}

/* Implementation of LoaderCallbacks.onLoadFinished */
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {

        case EXTERNAL_CURSOR_ID:
            mExternalCursor = data;
            break;
        default:
            return;
    }
    // TODO: should I use a mutex/synchronized block here?
    if (mExternalCursor != null) {
        Cursor mergeCursor = new MergeCursor(new Cursor[]{mExternalCursor});
        mAdapter.swapCursor(mergeCursor);
    }
}

/* Implementation of LoaderCallbacks.onLoaderReset */
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    // This is called when the last Cursor provided to onLoadFinished()
    // above is about to be closed.  We need to make sure we are no
    // longer using it.
    mAdapter.swapCursor(null);
}

@TargetApi(Build.VERSION_CODES.M)
private void checkReadStoragePermission() {
    if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
            DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (which == DialogInterface.BUTTON_POSITIVE) {

                        ActivityCompat.requestPermissions(RingdroidSelectActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, EXT_STORAGE_PERMISSION_REQ_CODE);


                    } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                        onPermissionsNotGranted();

                    }
                    dialog.dismiss();
                    finish();
                    startActivity(getIntent());
                }
            };
            new android.support.v7.app.AlertDialog.Builder(this)
                    .setTitle(R.string.permissions_title)
                    .setMessage(R.string.read_ext_permissions_message)
                    .setPositiveButton(R.string.btn_continue, onClickListener)
                    .setNegativeButton(R.string.btn_cancel, onClickListener)
                    .setCancelable(false)
                    .show();
            return;
        }
        ActivityCompat.requestPermissions(RingdroidSelectActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE}, EXT_STORAGE_PERMISSION_REQ_CODE);
        return;
    }

}

private void onPermissionsNotGranted() {
    Toast.makeText(this, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT).show();
    Log.v("tom", "JERRY");
}

最佳答案

查看您的调用堆栈,它确实可以帮助您缩小问题范围。

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
   at unnion.neelay.beatbox.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:123)
   at android.app.Activity.performCreate(Activity.java:6303)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)

例如,在您的调用堆栈中,您首先会抛出异常,NullPointerException,它会告诉您是什么导致了它。

java.lang.String.equals(java.lang.Object)

因此,您有一个 String,您正尝试对其调用 .equals,但 String 为 null。

现在,稍微低一点,它显示了发生此问题的行号。

unnion.neelay.beatbox.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:123)

因此,您在 RingdroidSelectActivityonCreate 中调用 .equals,位于 123 行。

但是,自从您发布错误后,您的代码可能已经更改,该行周围没有 .equals,但我认为它可能是您的 getExternalStroage().

String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
     showFinalAlert(getResources().getText(R.string.sdcard_readonly));
     return;
}

也许你没有这个或其他东西的许可。添加一些 null 检查,这将帮助您调试问题。

希望对您有所帮助!

编辑: 问题是 this 所以答案是

mWasGetContentIntent = Intent.ACTION_GET_CONTENT.equals(intent.getAction());

关于android - 运行时异常无法启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46019266/

有关android - 运行时异常无法启动 Activity的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  4. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  5. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  6. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  7. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  8. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  9. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  10. ruby - Sinatra:运行 rspec 测试时记录噪音 - 2

    Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/

随机推荐