Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio getSlotFromBufferLocked: unknown buffer error

Tags:

android

mysql

I want to make a simple login and register app, so the user can create an account. (name, username, password) I use WAMP and a MYSQL database where I store the accounts.

When I fill in the user info on the registration form and click register I get the following error:

09-14 09:30:39.864    2624-2638/com.example.appname.appname E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7115e0 09-14 09:30:48.632    2624-2638/com.example.appname.appname E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7125a0 09-14 09:30:51.940    2624-2638/com.example.appname.appname E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7125a0 

When I go check the database it didn't store the account.

MainActivity.java

import android.app.Activity; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View;  public class MainActivity extends Activity {      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);     }     public void userReg(View v)     {         startActivity(new Intent(this, Register.class));     }     public void userLogin(View view)     {       }   } 

Register.java

import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText;  public class Register extends Activity {     EditText ET_NAME,ET_USER_NAME,ET_USER_PASS;     String name,user_name,user_pass;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.register_layout);         ET_NAME = (EditText) findViewById(R.id.name);         ET_USER_NAME = (EditText) findViewById(R.id.new_user_name);         ET_USER_PASS = (EditText) findViewById(R.id.new_user_pass);     }      public void userReg(View view)     {         name = ET_NAME.getText().toString();         user_name = ET_USER_NAME.getText().toString();         user_pass = ET_USER_PASS.getText().toString();         String method = "register";         BackgroundTask backgroundTask = new BackgroundTask(Register.this);         backgroundTask.execute(method,name,user_name,user_pass);         finish();     } } 

Backgroundtask.java

import android.app.AlertDialog; import android.content.Context; import android.os.AsyncTask; import android.widget.Toast;  import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder;  public class BackgroundTask extends AsyncTask<String, Void, String> {     AlertDialog alertDialog;     Context ctx;      BackgroundTask(Context ctx) {         this.ctx = ctx;      }      @Override     protected void onPreExecute() {         super.onPreExecute();     }      @Override     protected String doInBackground(String... params) {         String reg_url = "http://10.0.2.2.2/webapp/register.php";         String login_url = "http://10.0.2.2.2/webapp/login.php";         String method = params[0];         if (method.equals("register")) {             String name = params[1];             String user_name = params[2];             String user_pass = params[3];             try {                 URL url = new URL(reg_url);                 HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();                 httpURLConnection.setRequestMethod("POST");                 httpURLConnection.setDoOutput(true);                 OutputStream OS = httpURLConnection.getOutputStream();                 BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));                 String data = URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(name, "UTF-8") + "&" +                         URLEncoder.encode("user_name", "UTF-8") + "=" + URLEncoder.encode(user_name, "UTF-8") + "&" +                         URLEncoder.encode("user_pass", "UTF-8") + "=" + URLEncoder.encode(user_pass, "UTF-8");                 bufferedWriter.write(data);                 bufferedWriter.flush();                 bufferedWriter.close();                 OS.close();                 InputStream IS = httpURLConnection.getInputStream();                 IS.close();                 return "Registration Success...";             } catch (MalformedURLException e) {                 e.printStackTrace();             } catch (IOException e) {                 e.printStackTrace();             }         }          return null;     }      @Override     protected void onProgressUpdate(Void... values) {         super.onProgressUpdate(values);     }      @Override     protected void onPostExecute(String result) {         Toast.makeText(ctx, result, Toast.LENGTH_LONG).show();     } } 

register.php

<?php require "init.php"; $name = $_POST["user"]; $user_name = $_POST["user_name"]; $user_pass = $_POST["user_pass"];  $sql_query = "insert into user_info values('$name','$user_name','$user_pass');";  if(mysqli_query($con,$sql_query)) { //echo"<h3> Data insertion success...</h3>"; } else{ //echo "Data insertion error..".mysqli_error($con); }    ?> 

init.php

<?php $db_name="myDBname"; $mysql_user = "root"; $mysql_pass = "root"; $server_name="localhost";  $con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name); if(!$con) { //echo"Connection Error".mysqli_connect_error(); } else { //echo"<h3> Database connection success.....</h3>"; }   ?> 
like image 268
Rob12 Avatar asked Sep 14 '15 09:09

Rob12


2 Answers

Edit:

This was a bug in Android that was fixed in later versions of Marshmallow

Original:

I believe that this is Marshmallow specific. Are you using a Marshmallow device?

I've noticed this error is printed out every time I switch between applications (doesn't matter which) or exit out of them, and when activities are destroyed.

I've tried running the same apps on two Nexus 5s - one running Lollipop and the other Marshmallow, and these log prints only appeared on the Marshmallow version - with every app, not just the one I'm building.

Not sure why this happens, but I opened a report here.

like image 121
Itai Hanski Avatar answered Oct 05 '22 16:10

Itai Hanski


I think you are finishing the context before backgrounTask finish, and Context you pass no longer exist.
You can try:

  • Use appContext : new BackgroundTask(Register.this.getApplicationContext());

  • Or, Wait for BackgroundTask finish : remove finish() after .execute(...) and add finish() onPostExecute

like image 38
Mario Avatar answered Oct 05 '22 15:10

Mario