无法从模拟器访问Firebase数据库。 E / Volley:BasicNetwork.performRequest:意外的响应代码400

时间:2017-07-14 13:20:44

标签: android firebase firebase-realtime-database firebase-authentication

我正在为我的应用进行用户注册和登录。在注册期间,我从FireBase数据库中获取Departments和Designations,在注册时,我将用户详细信息存储在Database中。但我无法从我的模拟器上的数据库中获取部门和指定,但它似乎在物理设备上正常工作。 我得到以下错误日志。

07-14 19:23:35.834 14256-14256/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:35.834 14256-14256/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:36.363 14271-14271/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:36.363 14271-14271/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:40.593 14283-14283/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:40.593 14283-14283/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:40.601 14281-14281/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:40.601 14281-14281/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:40.629 14281-14300/? E/art: Thread attaching while runtime is shutting down: Binder_1
07-14 19:23:40.869 14298-14298/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:40.869 14298-14298/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:41.256 14310-14310/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:41.256 14310-14310/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:41.515 14321-14321/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:41.515 14321-14321/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:42.377 1332-1332/? E/installd: Couldn't opendir /data/app/vmdl651364592.tmp: No such file or directory
07-14 19:23:42.508 1907-3373/com.google.android.gms.persistent E/NetworkScheduler.SR: Invalid parameter app
07-14 19:23:42.508 1907-3373/com.google.android.gms.persistent E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
07-14 19:23:42.772 1907-3373/com.google.android.gms.persistent E/NetworkScheduler.SR: Invalid parameter app
07-14 19:23:42.772 1907-3373/com.google.android.gms.persistent E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
07-14 19:23:42.964 14355-14355/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:23:42.964 14355-14355/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:23:43.032 14377-14377/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_dependencies_apk.apk@classes.dex: Permission denied
07-14 19:23:43.081 1934-2205/com.android.launcher3 E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaaae6960
07-14 19:23:43.208 14379-14379/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_0_apk.apk@classes.dex: Permission denied
07-14 19:23:43.225 14381-14381/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_1_apk.apk@classes.dex: Permission denied
07-14 19:23:43.239 14385-14385/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_2_apk.apk@classes.dex: Permission denied
07-14 19:23:43.256 14387-14387/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_3_apk.apk@classes.dex: Permission denied
07-14 19:23:43.284 14391-14391/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_4_apk.apk@classes.dex: Permission denied
07-14 19:23:43.312 14393-14393/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_5_apk.apk@classes.dex: Permission denied
07-14 19:23:43.337 14395-14395/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_6_apk.apk@classes.dex: Permission denied
07-14 19:23:43.359 14397-14397/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_7_apk.apk@classes.dex: Permission denied
07-14 19:23:43.377 14399-14399/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_8_apk.apk@classes.dex: Permission denied
07-14 19:23:43.392 14401-14401/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_slice_9_apk.apk@classes.dex: Permission denied
07-14 19:23:43.953 1244-1307/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
07-14 19:23:45.589 2419-3356/com.google.android.gms E/Volley: [270] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:23:46.645 2419-3358/com.google.android.gms E/Volley: [272] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:23:47.768 2419-3357/com.google.android.gms E/Volley: [271] BasicNetwork.performRequest: Unexpected response code 400 
07-14 19:23:48.207 14364-14411/apkcrew.teststationary E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa3560e60
07-14 19:23:49.046 2419-3359/com.google.android.gms E/Volley: [273] BasicNetwork.performRequest: Unexpected response code 400 
07-14 19:23:51.666 2419-3356/com.google.android.gms E/Volley: [270] BasicNetwork.performRequest: Unexpected response code 400 
07-14 19:23:54.424 2419-3358/com.google.android.gms E/Volley: [272] BasicNetwork.performRequest: Unexpected response code 400 
07-14 19:23:57.856 2419-3357/com.google.android.gms E/Volley: [271] BasicNetwork.performRequest: Unexpected response code 400 
07-14 19:24:00.767 2419-3359/com.google.android.gms E/Volley: [273] BasicNetwork.performRequest: Unexpected response code 400 
07-14 19:24:07.430 2419-3356/com.google.android.gms E/Volley: [270] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:24:12.981 2419-3358/com.google.android.gms E/Volley: [272] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:24:20.344 2419-3357/com.google.android.gms E/Volley: [271] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:24:28.708 2419-3359/com.google.android.gms E/Volley: [273] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:24:41.736 2419-3356/com.google.android.gms E/Volley: [270] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:25:04.085 2419-3358/com.google.android.gms E/Volley: [272] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:25:18.285 2419-3357/com.google.android.gms E/Volley: [271] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:25:35.675 2419-3359/com.google.android.gms E/Volley: [273] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:25:56.498 2419-3356/com.google.android.gms E/Volley: [270] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:26:11.995 2419-3358/com.google.android.gms E/Volley: [272] BasicNetwork.performRequest: Unexpected response code 400
07-14 19:26:29.679 16849-16849/? E/memtrack: Couldn't load memtrack module (No such file or directory)
07-14 19:26:29.679 16849-16849/? E/android.os.Debug: failed to load memtrack module: -2
07-14 19:26:29.695 1627-1675/system_process E/InputDispatcher: channel '26c07d9 apkcrew.teststationary/apkcrew.teststationary.RegisterActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-14 19:26:29.696 1627-1675/system_process E/InputDispatcher: channel '58d303e apkcrew.teststationary/apkcrew.teststationary.LoginActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-14 19:26:29.780 16875-16875/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/x86/data@app@apkcrew.teststationary-1@split_lib_dependencies_apk.apk@classes.dex: Permission denied

这是我的Java代码

RegisterActivity Class

   package apkcrew.teststationary;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import android.util.Log;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.util.Log;

public class RegisterActivity extends AppCompatActivity{

    private EditText username;
    private EditText email;
    private EditText password;
    private Spinner deptspinner;
    private Spinner desigspinner;
    private Button regbtn;
    private ProgressDialog progressDialog;
    private ProgressDialog loadingDialog;
    private FirebaseAuth mAuth;
//    private FirebaseAuth.AuthStateListener mAuthListener;
    private DatabaseReference firebaseDatabase,deptref,desigref;
    private static final String TAG = "registrationlog";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        Log.i(TAG,"OnCreate");

        username = (EditText)findViewById(R.id.user);
        password = (EditText)findViewById(R.id.passw);
        email = (EditText)findViewById(R.id.email);
        deptspinner = (Spinner)findViewById(R.id.depspinner);
        desigspinner = (Spinner)findViewById(R.id.desigspinner);
        regbtn = (Button)findViewById(R.id.regbutton);
        progressDialog = new ProgressDialog(this);
        loadingDialog = new ProgressDialog(this);

        mAuth = FirebaseAuth.getInstance();
//        mAuthListener = new FirebaseAuth.AuthStateListener() {
//            @Override
//            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
//                FirebaseUser user = firebaseAuth.getCurrentUser();
//                if(user!=null)
//                {
//                    Log.i(TAG,"onAutStateChanged:signed_in:"+ user.getUid());
//                }
//                else{
//                    Log.i(TAG,"onAutStateChanged:signed_out");
//                }
//            }
//        };
        firebaseDatabase = FirebaseDatabase.getInstance().getReference("Users");

        deptref = FirebaseDatabase.getInstance().getReference("Departments");
        desigref = FirebaseDatabase.getInstance().getReference("Designations");

        loadingDialog.setMessage("Loading...");
        loadingDialog.show();
//        set up department spinner
        Log.i(TAG,"Calling getDepartments");
        getDepartments();

//        Set up desig spinner
        Log.i(TAG,"Calling getDesignations");
        getDesignations();

        loadingDialog.dismiss();
//        register btn listener
        regbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG,"Clicked Register");
                registerUser();
            }
        });
    }

//    fills list of departments from database
    private void getDepartments() {
        Log.i(TAG,"Inside getDepartments");
        final List<String> deptlist = new ArrayList<String>();

        deptref.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Log.i(TAG,"DatasnapShot children count(departments): "+dataSnapshot.getChildrenCount());
                for(DataSnapshot dsp: dataSnapshot.getChildren()){
                    Log.i(TAG, dsp.getValue(String.class));
                    deptlist.add(dsp.getValue(String.class));
                    ArrayAdapter<String> deptadapter = new ArrayAdapter<String>(RegisterActivity.this,android.R.layout.simple_spinner_item,deptlist);
                    deptadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

                    deptspinner.setAdapter(deptadapter);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                throw databaseError.toException();
            }
        });
        Log.i(TAG,"DeptList size before returning: "+deptlist.size());
    }

//    fills list of designations from database
    private void getDesignations(){
        Log.i(TAG,"Inside getDesignations");
        final List<String> desiglist = new ArrayList<String>();

        desigref.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Log.i(TAG,"DatasnapShot children count(designations): "+dataSnapshot.getChildrenCount());
                for(DataSnapshot dsp: dataSnapshot.getChildren()){
                    Log.i(TAG,dsp.getValue(String.class));
                    desiglist.add(dsp.getValue(String.class));
                    ArrayAdapter<String> desigadapter = new ArrayAdapter<String>(RegisterActivity.this,android.R.layout.simple_spinner_item,desiglist);
                    desigadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

                    desigspinner.setAdapter(desigadapter);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                throw databaseError.toException();
            }
        });
        Log.i(TAG,"DesigList Size: "+ desiglist.size());
    }

//    @Override
//    public void onStart() {
//        super.onStart();
//        mAuth.addAuthStateListener(mAuthListener);
//    }
//
//    @Override
//    public void onStop() {
//        super.onStop();
//        if (mAuthListener != null) {
//            mAuth.removeAuthStateListener(mAuthListener);
//        }
//    }

    private void registerUser(){
        Log.i(TAG,"Register User");
        String emailtext = email.getText().toString().trim();
        String passtext = password.getText().toString().trim();

        String[] namearray = new String[2];
        StringBuilder userNameBuilder = new StringBuilder();

        String usernametext = username.getText().toString().trim();
        String finalUserName;
        if(usernametext.contains(" "))
        {
            namearray = usernametext.split(" ");
            userNameBuilder.append(namearray[0]).append(namearray[1]);
            finalUserName = userNameBuilder.toString();
        }
        else{
            finalUserName = usernametext;
        }


        String deptselected = deptspinner.getSelectedItem().toString();
        String desigSelected = desigspinner.getSelectedItem().toString();

        if(TextUtils.isEmpty(emailtext))
        {
            Toast.makeText(this,"Please enter the email",Toast.LENGTH_LONG).show();
            return;
        }
        if(TextUtils.isEmpty(passtext))
        {
            Toast.makeText(this,"Please enter the password",Toast.LENGTH_LONG).show();
            return;
        }

        if(TextUtils.isEmpty(usernametext))
        {
            Toast.makeText(this,"Please enter the username",Toast.LENGTH_LONG).show();
            return;
        }

        if(TextUtils.isEmpty(deptselected))
        {
            Toast.makeText(this,"Please select the department",Toast.LENGTH_LONG).show();
            return;
        }
        if(TextUtils.isEmpty(emailtext))
        {
            Toast.makeText(this,"Please select the designation",Toast.LENGTH_LONG).show();
            return;
        }

//        validations are fine
        progressDialog.setMessage("Registering User...");
        progressDialog.show();

        mAuth.createUserWithEmailAndPassword(finalUserName+"_iocl@gmail.com",passtext)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        progressDialog.dismiss();
                        if(task.isSuccessful())
                        {
                            Log.i(TAG,"Registered Success");
                            Toast.makeText(RegisterActivity.this,"User registered successfully",Toast.LENGTH_LONG).show();
                            finish();
                            startActivity(new Intent(RegisterActivity.this,LoginActivity.class));
                        }
                        else
                        {
                            Toast.makeText(RegisterActivity.this,"Failed to register. Please try again",Toast.LENGTH_LONG).show();
                        }
                    }
                });

        HashMap<String,String> userdetails = new HashMap<>();
//        userdetails.put("Name",usernametext);
        userdetails.put("Email",emailtext);
        userdetails.put("Password",passtext);
        userdetails.put("Department",deptselected);
        userdetails.put("Designation",desigSelected);


        String id = usernametext;
        firebaseDatabase.child(id).setValue(userdetails);
    }
}

build.gradle(Modulo:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "apkcrew.teststationary"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:11.0.2'
    compile 'com.google.firebase:firebase-database:11.0.2'
    compile 'com.android.support:design:25.3.1'
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
    compile 'com.itextpdf:itextg:5.5.9'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

的AndroidManifest.xml

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

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

    <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=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity" />
        <activity android:name=".DetailActivity" />
        <activity android:name=".ViewRequest" />
        <activity android:name=".EmployeeInfo" />
        <activity android:name=".NewItemRequest" />
        <activity android:name=".FirstScreen" />
        <activity android:name=".AdminActivity" />
        <activity android:name=".ApproveRequests" />
        <activity android:name=".ApprovalConfirm" />
        <activity android:name=".AdminDetails"></activity>
    </application>

</manifest>

0 个答案:

没有答案