Android错误getSlotFromBufferLocked:未知缓冲区:0xa9fb8d90

时间:2016-07-26 08:53:46

标签: android android-sqlite

我正在使用一个Android应用程序,它使用material-intro dependencies作为介绍幻灯片, 但是当幻灯片完成并尝试从幻灯片(MaterialintroActivity)切换到我的主要活动时,应用程序崩溃了。

logcat的

 07-26 12:42:19.566 897-944/com.naive.LISTY E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa9fb8d90

AppManifest代码

<application
    android:allowBackup="true"
    android:icon="@mipmap/icon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainIntroActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity"/>
</application>

MainIntroActivity

public class MainIntroActivity extends IntroActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {

    setFullscreen(true);
    super.onCreate(savedInstanceState);

    addSlide(new SimpleSlide.Builder()
            .title(R.string.title)
            .description(R.string.description)
            .image(R.mipmap.ic_launcher)
            .background(R.color.background)
            .backgroundDark(R.color.background_dark)
            .buttonCtaClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v)
                {
                    Intent main=new Intent(MainIntroActivity.this, MainActivity.class);
                    startActivity(main);
                }
            })
            .build());
}}

MainActivity代码

public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";

private TaskDbHelper mHelper;
private ListView mTaskListView;
private ArrayAdapter<String> mAdapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

      if(!prefs.getBoolean("new1",false)){

        //Only 1st time run code here

        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("new1", true);
        editor.commit();
     }*/

    setContentView(R.layout.activity_main);
    mHelper = new TaskDbHelper(this);
    mTaskListView = (ListView) findViewById(R.id.list_todo);
    updateUI();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    return super.onCreateOptionsMenu(menu);
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_add_task:

        final EditText taskEditText = new EditText(this);
        AlertDialog dialog = new AlertDialog.Builder(this)
                .setTitle("Add new task")
               // .setMessage("What do you want to do next?")
                .setView(taskEditText)
                .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String task = String.valueOf(taskEditText.getText());
                        if(task != null && !task.isEmpty()) {
                            SQLiteDatabase db = mHelper.getWritableDatabase();
                            ContentValues values = new ContentValues();
                            values.put(TaskContract.TaskEntry.COL_TASK_TITLE, task);
                            db.insertWithOnConflict(TaskContract.TaskEntry.TABLE,
                                    null,
                                    values,
                                    SQLiteDatabase.CONFLICT_REPLACE);
                            updateUI();
                            db.close();
                        } else {

                        }
                    }
                })
                .setNegativeButton("Cancel", null)
                .create();
        dialog.show();

        default:
            return super.onOptionsItemSelected(item);
    }
}

private void updateUI() {
    ArrayList<String> taskList = new ArrayList<>();
    SQLiteDatabase db = mHelper.getReadableDatabase();
    Cursor cursor = db.query(TaskContract.TaskEntry.TABLE,
            new String[]{TaskContract.TaskEntry._ID, TaskContract.TaskEntry.COL_TASK_TITLE},
            null, null, null, null, null);
    while (cursor.moveToNext()) {
        int idx = cursor.getColumnIndex(TaskContract.TaskEntry.COL_TASK_TITLE);
        taskList.add(cursor.getString(idx));
    }

    if (mAdapter == null) {
        mAdapter = new ArrayAdapter<>(this,
                R.layout.item_todo,
                R.id.task_title,
                taskList);
        mTaskListView.setAdapter(mAdapter);
    } else {
        mAdapter.clear();
        mAdapter.addAll(taskList);
        mAdapter.notifyDataSetChanged();
    }

    cursor.close();
    db.close();
}

public void deleteTask(View view) {
    View parent = (View) view.getParent();
    TextView taskTextView = (TextView) parent.findViewById(R.id.task_title);
    String task = String.valueOf(taskTextView.getText());
    SQLiteDatabase db = mHelper.getWritableDatabase();
    db.delete(TaskContract.TaskEntry.TABLE,
            TaskContract.TaskEntry.COL_TASK_TITLE + " = ?",
            new String[]{task});
    db.close();
    updateUI();
}
}

5 个答案:

答案 0 :(得分:0)

您是否使用棉花糖版本进行测试?因为我发现了这个问题:https://code.google.com/p/android/issues/detail?id=192357

可以尝试从以下位置更改oncreate函数:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.<YOUR_XML_FILE_NAME>);

对此:

@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    setContentView(R.layout.<YOUR_XML_FILE_NAME>);
}

如果问题仍然存在,请尝试将Android版本更新为Android 6.0.1中的问题。希望它有所帮助。

答案 1 :(得分:0)

在我的情况下,在appmaniefest中将minSdkver从9更改为16之后,错误被破坏了。我做了撤消minsdk版本更改。它解决了错误。最初我试图使用至少要求最低版本16的日历和日期。

答案 2 :(得分:0)

重新启动Android Studio和您的模拟器。重启后它会起作用。

答案 3 :(得分:0)

<application
    android:allowBackup="true"
    android:icon="@mipmap/icon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainIntroActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity"/>
</application>

答案 4 :(得分:0)

  

添加了互联网权限

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.projectx.store">

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

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".ViewAllStore" />
            <activity android:name=".ViewStore"></activity>
        </application>

    </manifest>