与Facebook集成并按帐户创建时,出现了这些运行时错误,该如何解决?

时间:2018-10-20 08:40:45

标签: java android facebook android-studio facebook-javascript-sdk

嗨,我在运行时遇到了这些错误, 当我第一次与Facebook集成时,我运行应用程序会给我该错误

  

无效的范围用户朋友

然后我尝试更改权限,例如电子邮件,basic_profile等,但是现在当我运行该应用程序时,它登录但仍保留在CardHeader中,而没有转到我的LoginActivity,只是facebook的登录按钮已更改为注销。之后,现在我的应用在运行和调试时崩溃,在我给setText用户配置文件的名称和图像的方法中,它会给我MainActivity的错误。

,我在应用程序中创建了一个用于自定义帐户的本地数据库,但是当我单击以单击创建帐户和NullPointerExceptions方法时,当数据发布到数据库中时,它也给我NullPointerExceptions错误我自己创建的内容不适用于该活动 但是当我尝试登录时,isInputField方法有效,但是当我在插入电子邮件和密码后单击“登录”按钮时,我的应用程序崩溃并在isInputField方法中给出了错误

  

未找到此类列user_password

但是当我检查数据库中的表时,有verifyFromSqlite列。

因此,要消除所有这些错误,我应该怎么做,请帮助我,我对此感到非常担心,因为这是我的最后一个项目。 我附上我所有的user_friendLoginActivitySignUpActivity和数据库类的代码

MainActivity Java类代码

LoginActivity

public class LoginActivity extends AppCompatActivity implements View.OnClickListener { private CallbackManager callbackManager; private AccessTokenTracker accessTokenTracker; private ProfileTracker profileTracker; private final AppCompatActivity activity=LoginActivity.this; private NestedScrollView nestedScrollView; private TextInputLayout textInputLayoutEmail; private TextInputLayout textInputLayoutPassword; private TextInputEditText textInputEditTextEmail; private TextInputEditText textInputEditTextPassword; private AppCompatButton login; private AppCompatTextView forgottonPassword; private AppCompatTextView linkRegiter; private InputValidation inputValidation; private DatabaseHelper databaseHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); setContentView(R.layout.activity_login); fbLogin(); if (getSupportActionBar()!=null) { getSupportActionBar().hide(); } initViews(); initListeners(); initObjects(); } protected void fbLogin(){ callbackManager=CallbackManager.Factory.create(); accessTokenTracker=new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken currentToken) { } }; profileTracker=new ProfileTracker() { @Override protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { nextActivity(newProfile); } }; accessTokenTracker.startTracking(); profileTracker.startTracking(); LoginButton loginButton = (LoginButton) findViewById(R.id.login_button); FacebookCallback<LoginResult> callback= new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Profile profile= Profile.getCurrentProfile(); nextActivity(profile); } @Override public void onCancel() { } @Override public void onError(FacebookException error) { } }; loginButton.setReadPermissions("user_friends"); loginButton.registerCallback(callbackManager, callback); } @Override protected void onResume() { super.onResume(); Profile profile= Profile.getCurrentProfile(); nextActivity(profile); } @Override protected void onPause() { super.onPause(); } @Override protected void onStop() { super.onStop(); accessTokenTracker.stopTracking(); profileTracker.stopTracking(); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode,resultCode,data); } private void nextActivity(Profile profile){ if (profile!=null){ Intent main = new Intent(LoginActivity.this,MainActivity.class); main.putExtra("name",profile.getFirstName()); main.putExtra("imageUrl",profile.getProfilePictureUri(100,80)).toString(); // main.putExtra("id", profile.getId()); startActivity(main); } } private void initViews(){ nestedScrollView= (NestedScrollView) findViewById(R.id.nestedScrollView) ; textInputLayoutEmail= (TextInputLayout) findViewById(R.id.textInputLayoutEmail); textInputLayoutPassword= (TextInputLayout) findViewById(R.id.textInputLayoutPassword); textInputEditTextEmail= (TextInputEditText) findViewById(R.id.textInputEditTextEmail); textInputEditTextPassword= (TextInputEditText) findViewById(R.id.textInputEditTextPassword); Log.e("textinputedittextmail",textInputEditTextEmail.toString()); login=(AppCompatButton) findViewById(R.id.login); linkRegiter= (AppCompatTextView) findViewById(R.id.linkRegister); } private void initListeners(){ login.setOnClickListener(this); linkRegiter.setOnClickListener(this); } public void initObjects(){ databaseHelper=new DatabaseHelper(activity); inputValidation=new InputValidation(activity); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.login: Log.v("abc", textInputEditTextEmail.getText().toString()); verifyFromSQLite(); break; case R.id.linkRegister: Intent intentRegister= new Intent(getApplicationContext(),SignupActivity.class); startActivity(intentRegister); break; } } private void verifyFromSQLite(){ if (!inputValidation.isInputEditTextFilled(textInputEditTextEmail, textInputLayoutEmail, "Please Enter Valid Email")){ return;} if (!inputValidation.isInputEditTextEmail(textInputEditTextEmail, textInputLayoutEmail, "Please Enter Valid Email")) return; if (!inputValidation.isInputEditTextFilled(textInputEditTextPassword, textInputLayoutPassword, "Please Enter Valid Password")) return; if (databaseHelper.checkUser(textInputEditTextEmail.getText().toString().trim(), textInputEditTextPassword.getText().toString().trim())){ Intent accountIntent= new Intent(activity, MainActivity.class); accountIntent.putExtra("Email",textInputEditTextEmail.getText().toString().trim()); emptyInputEditText(); startActivity(accountIntent); }else { Snackbar.make(nestedScrollView, "Please Enter Valid Email or Password", Snackbar.LENGTH_LONG).show(); } } private void emptyInputEditText(){ textInputEditTextEmail.setText(""); textInputEditTextPassword.setText(""); } } Java类代码:

SignUp

databaseHelper javaclass代码

public class SignupActivity extends AppCompatActivity implements View.OnClickListener {

    private final AppCompatActivity activity=SignupActivity.this;

    private NestedScrollView nestedScrollView;

    private TextInputLayout textInputLayoutFirstName;
    private TextInputLayout textInputLayoutLastName;
    private TextInputLayout textInputLayoutEmail;
    private TextInputLayout textInputLayoutPassword;
    private TextInputLayout textInputLayoutConfirmPassword;

    private TextInputEditText textInputEditTextFirstName;
    private TextInputEditText textInputEditTextLastName;
    private TextInputEditText textInputEditTextEmail;
    private TextInputEditText textInputEditTextPassword;
    private TextInputEditText textInputEditTextConfirmPassword;

    private AppCompatButton appCompatButtonCreateAccount;
    private AppCompatTextView linklogin;

    private InputValidation inputValidation;
    private DatabaseHelper databaseHelper;
    private User user;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);

        if (getSupportActionBar()!=null)
        {
            getSupportActionBar().hide();
        }

        initViews();
        initListeners();
        initObjects();
    }

    private void initViews(){
        nestedScrollView=(NestedScrollView) findViewById(R.id.nestedScrollView);

        textInputLayoutFirstName= (TextInputLayout) findViewById(R.id.textInputLayoutFirstName);
        textInputLayoutLastName= (TextInputLayout) findViewById(R.id.textInputLayoutLastName);
        textInputLayoutEmail= (TextInputLayout) findViewById(R.id.textInputLayoutEmail);
        textInputLayoutPassword= (TextInputLayout) findViewById(R.id.textInputLayoutPassword);
        textInputLayoutConfirmPassword= (TextInputLayout) findViewById(R.id.textInputLayoutConfirmPassword);

        textInputEditTextEmail= (TextInputEditText) findViewById(R.id.textInputEditTextEmail);
        textInputEditTextPassword= (TextInputEditText) findViewById(R.id.textInputEditTextPassword);

        appCompatButtonCreateAccount=(AppCompatButton) findViewById(R.id.appCompatButtonCreateAccount);
        linklogin= (AppCompatTextView) findViewById(R.id.linklogin);
    }

    private void initListeners(){
        appCompatButtonCreateAccount.setOnClickListener(this);
        linklogin.setOnClickListener(this);
    }

    public  void initObjects(){
        databaseHelper=new DatabaseHelper(activity);
        inputValidation=new InputValidation(activity);
        user=new User();

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.appCompatButtonCreateAccount:
                postDataToSQLite();
                break;
            case R.id.linklogin:
                finish();
                break;
        }

    }


    private void postDataToSQLite(){
        if (!inputValidation.isInputEditTextFilled(textInputEditTextFirstName, textInputLayoutFirstName, "Please Enter Full Name"))
            return;
        if (!inputValidation.isInputEditTextFilled(textInputEditTextLastName, textInputLayoutLastName, "Please Enter Full Name"))
            return;
        if (!inputValidation.isInputEditTextEmail(textInputEditTextEmail, textInputLayoutEmail, "Please Enter Valid Email"))
            return;
        if (!inputValidation.isInputEditTextFilled(textInputEditTextEmail, textInputLayoutEmail,"Please Enter Valid Email" ))
            return;
        if (!inputValidation.isInputEditTextFilled(textInputEditTextPassword, textInputLayoutPassword, "Please Enter Password"))
            return;

        if (!databaseHelper.checkUser(textInputEditTextEmail.getText().toString().trim())){
            user.setFirstName(textInputEditTextFirstName.getText().toString().trim());
            user.setLastName(textInputEditTextLastName.getText().toString().trim());
            user.setEmail(textInputEditTextEmail.getText().toString().trim());
            user.setEmail(textInputEditTextPassword.getText().toString().trim());

            databaseHelper.addUser(user);

            Snackbar.make(nestedScrollView, "Registration Successful",Snackbar.LENGTH_LONG).show();
            emptyInputEditText();
        }else {
            Snackbar.make(nestedScrollView, "Already a member Please Login", Snackbar.LENGTH_LONG).show();
       }
    }

    private void emptyInputEditText(){
        textInputEditTextFirstName.setText("");
        textInputEditTextLastName.setText("");
        textInputEditTextEmail.setText("");
        textInputEditTextPassword.setText("");
        textInputEditTextConfirmPassword.setText("");
    }
}

inputValidation Java类代码

public class DatabaseHelper extends SQLiteOpenHelper {

    public static final int DATABASE_VERSION=1;
    public static final String DATABASE_NAME="userManager.db";
    public static final String TABLE_USER="user";

    public static final String COLUMN_USER_ID="user_id";
    public static final String COLUMN_USER_FIRSTNAME="user_firstName";
    public static final String COLUMN_USER_LASTNAME="user_lastName";
    public static final String COLUMN_USER_EMAIL="user_email";
    public static final String COLUMN_USER_PASSWORD="user_password";

    public String CREATE_USER_TABLE="CREATE TABLE "+TABLE_USER+"("
            + COLUMN_USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+ COLUMN_USER_FIRSTNAME + " TEXT,"
            + COLUMN_USER_LASTNAME+ " TEXT,"+COLUMN_USER_EMAIL + " TEXT,"+COLUMN_USER_PASSWORD
            +" TEXT" + ")";
    private String DROP_USER_TABLE="DROP TABLE IF EXISTS "+TABLE_USER;


    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_USER_TABLE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(DROP_USER_TABLE);
        onCreate(db);

    }

    public void addUser(User user){
        SQLiteDatabase db=this.getWritableDatabase();
        ContentValues values=new ContentValues();
        values.put(COLUMN_USER_FIRSTNAME, user.getFirstName());
        values.put(COLUMN_USER_LASTNAME, user.getLastName());
        values.put(COLUMN_USER_EMAIL, user.getEmail());
        values.put(COLUMN_USER_PASSWORD, user.getPassword());

        db.insert(TABLE_USER, null,values);
        db.close();
    }

    public boolean checkUser(String email){
        String[] columns={COLUMN_USER_ID};

        SQLiteDatabase db=this.getWritableDatabase();
        String selection= COLUMN_USER_EMAIL+ " = ?";
        String [] selectionArgs={email };

        Cursor cursor= db.query(TABLE_USER,
                columns,
                selection,
                selectionArgs,
                null,
                null,
                null);
        int cursorCount=cursor.getCount();
        cursor.close();
        db.close();
        if (cursorCount>0){
            return true;
        }
        return false;

    }

    public boolean checkUser(String email , String password){
        String[] columns={
                COLUMN_USER_ID
        };

        SQLiteDatabase db=this.getWritableDatabase();
        String selection= COLUMN_USER_EMAIL+ " = ?" + " AND " + COLUMN_USER_PASSWORD+" =?";
        String [] selectionArgs ={ email, password };

        Cursor cursor= db.query(TABLE_USER,
                columns,
                selection,
                selectionArgs,
                null,
                null,
                null);
        int cursorCount=cursor.getCount();
        cursor.close();
        db.close();
        if (cursorCount>0){
            return true;
        }
        return false;

    }
}

主要Activity类的Java代码

public class InputValidation {

    private Context context;

    public InputValidation(Context context){

        this.context=context;
    }

    public boolean isInputEditTextFilled(TextInputEditText textInputEditText, TextInputLayout textInputLayout, String message){
        String value = "";
        value=textInputEditText.getText().toString().trim();
        if (value.isEmpty()){
            textInputLayout.setError(message);
            hideKeyboardFrom(textInputEditText);
            return false;
        }else {
            textInputLayout.setErrorEnabled(false);
        }
        return true;

    }

    public boolean isInputEditTextEmail(TextInputEditText textInputEditText, TextInputLayout textInputLayout, String message){
        String value = textInputEditText.getText().toString().trim();
        if (value.isEmpty()|| !Patterns.EMAIL_ADDRESS.matcher(value).matches()){
            textInputLayout.setError(message);
            hideKeyboardFrom(textInputEditText);
            return false;
        }else {
            textInputLayout.setErrorEnabled(false);
        }
        return true;

    }

    public boolean isInputEditTextMatches(TextInputEditText textInputEditText, TextInputEditText textInputEditText2 , TextInputLayout textInputLayout, String message){
        String value1 = "";
        value1=textInputEditText.getText().toString().trim();
        String value2 = "";
        value2=textInputEditText.getText().toString().trim();
        if (!value1.contentEquals(value2)){
            textInputLayout.setError(message);
            hideKeyboardFrom(textInputEditText);
            return false;
        }else {
            textInputLayout.setErrorEnabled(false);
        }
        return true;

    }

    private void hideKeyboardFrom(View view){
        InputMethodManager inputMethodManager= (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}

我没有附加public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { private ShareDialog shareDialog; private String name=" "; private String imageUrl=" "; //private String id=" "; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(this); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); fabShare(); getAndSetData(); new MainActivity.DownloadImage((ImageView)findViewById(R.id.profilePic)); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); if (savedInstanceState==null) { getSupportFragmentManager().beginTransaction().replace(R.id.content_main, new ActivityActivity()).commit(); navigationView.setCheckedItem(R.id.nav_activity); } } private void fabShare(){ FloatingActionButton fab =(FloatingActionButton)findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShareLinkContent content= new ShareLinkContent.Builder().build(); shareDialog.show(content); } }); } private void getAndSetData(){ Bundle inBundle=getIntent().getExtras(); name=inBundle.get("name").toString(); imageUrl=inBundle.get("imageUrl").toString(); //id=inBundle.get("id").toString(); TextView yourName=(TextView) findViewById(R.id.yourName); TextView yourId=(TextView) findViewById(R.id.yourId); yourName.setText(name); //yourId.setText(id); } @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_activity) { getSupportFragmentManager().beginTransaction().replace(R.id.content_main, new ActivityActivity()).commit(); } else if (id == R.id.nav_history) { getSupportFragmentManager().beginTransaction().replace(R.id.content_main, new HistoryActivity()).commit(); } else if (id == R.id.nav_settings) { } else if (id == R.id.nav_logout){ LoginManager.getInstance().logOut(); Intent login=new Intent(MainActivity.this,LoginActivity.class); startActivity(login); finish(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } public class DownloadImage extends AsyncTask<String,Void ,Bitmap>{ ImageView bmImage; public DownloadImage(ImageView bmImage){ this.bmImage=bmImage; } @Override protected Bitmap doInBackground(String... urls) { String urlDisplay=urls[0]; Bitmap bitmap=null; try { InputStream inputStream= new java.net.URL(urlDisplay).openStream(); bitmap= BitmapFactory.decodeStream(inputStream); }catch (Exception e){ Log.e("Error",e.getMessage()); e.printStackTrace(); } return bitmap; } @Override protected void onPostExecute(Bitmap bitmap) { bmImage.setImageBitmap(bitmap); } } } 代码,因为它超出了限制和用户类别 在用户类中,只有用于数据库列的getter和setter。

0 个答案:

没有答案