-5

i have attached the registeractivity.xml file, registeractivity.java file, mainactivity.java file, manifest file and logcat.

Whenever i run this application after entering username, email and password when i click on sign-up button the stops working.

XML File:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.user.loginapp.RegisterActivity">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:hint="Username"
        android:ems="10"
        android:id="@+id/usernameRegistereditText"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:hint="E-mail"
        android:id="@+id/emailRegistereditText"
        android:layout_below="@+id/usernameRegistereditText"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:hint="Password"
        android:id="@+id/passwordRegistereditText"
        android:layout_below="@+id/emailRegistereditText"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Sign Up"
        android:id="@+id/signupbutton"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

RegisterActivity.Java File:

package com.example.user.loginapp;

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.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;

public class RegisterActivity extends AppCompatActivity {

    protected EditText mUsername;
    protected EditText mEmail;
    protected EditText mPassword;
    protected Button mSignup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        //initialise
        mUsername=(EditText)findViewById(R.id.usernameRegistereditText);
        mEmail=(EditText)findViewById(R.id.emailRegistereditText);
        mPassword=(EditText)findViewById(R.id.passwordRegistereditText);
        mSignup=(Button)findViewById(R.id.signupbutton);

        //Listen to button
        mSignup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //get username password and email and convert to string
                String username=mUsername.getText().toString().trim();
                String email=mEmail.getText().toString().trim();
                String password=mPassword.getText().toString().trim();

                // store user to parse
                ParseUser user=new ParseUser();
                user.setUsername(username);
                user.setEmail(email);
                user.setPassword(password);
                user.signUpInBackground(new SignUpCallback() {
                    @Override
                    public void done(ParseException e) {
                        if(e==null){
                            Toast.makeText(RegisterActivity.this,"Sign-up successful",Toast.LENGTH_LONG).show();
                        }else{
                            //error message
                        }
                    }
                });
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_register, 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);
    }
}

mainActivity.java file:

import com.parse.Parse;
import com.parse.ParseObject;
import com.parse.ParseObject.*;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Parse.enableLocalDatastore(this);

        Parse.initialize(this);
        ParseObject testObject = new ParseObject("TestObject");
        testObject.put("foo", "bar");
        testObject.saveInBackground();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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);
    }
}

Manifest file:

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.parse.APPLICATION_ID"
            android:value="E9N4CpvflF5WfGVaQ5kBXYHgNA1Z2BE0cXhgc82j" />
        <meta-data
            android:name="com.parse.CLIENT_KEY"
            android:value="IybWtApcNpi8Ky5odgHSAp34oyaxkFw0Jz9voH5U" />

        <activity
            android:name=".RegisterActivity"
            android:label="@string/title_activity_register" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

LOGCAT:

    01-26 16:40:41.028    3836-3836/com.example.user.loginapp E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache
01-26 16:40:41.048    3836-3836/com.example.user.loginapp E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
01-26 16:41:00.912    3836-3836/com.example.user.loginapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: You must create this type of ParseObject using ParseObject.create() or the proper subclass.
            at com.parse.ParseObject.<init>(ParseObject.java:365)
            at com.parse.ParseObject.<init>(ParseObject.java:334)
            at com.parse.ParseUser.<init>(ParseUser.java:162)
            at com.example.user.loginapp.RegisterActivity$1.onClick(RegisterActivity.java:43)
            at android.view.View.performClick(View.java:4240)
            at android.view.View$PerformClick.run(View.java:17721)
            at android.os.Handler.handleCallback(Handler.java:730)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
John Joe
  • 12,412
  • 16
  • 70
  • 135
Guneet Kaur
  • 544
  • 1
  • 8
  • 26
  • 4
    That is a code dump with no description of what it's supposed to do. No one is going to want to help you. Please narrow the problem down to a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) and you have a better chance of getting some constructive responses. – Mage Xy Jan 26 '16 at 21:10
  • @MageXy sir i wanted to make a login app but so i made two activities:main & register ... – Guneet Kaur Jan 26 '16 at 21:12
  • The error is saying that the ParseObject must be created with its create() method. You have just newed one up without using its factory method. You want something like this:ParseObject testObject = ParseObject.create("TestObject"); – voam Jan 26 '16 at 21:13
  • @voam hey how can i use factory method in this ...please elaborate coz m a novice in this field. – Guneet Kaur Jan 26 '16 at 21:17
  • I've moved my comment to a seperate answer. – voam Jan 26 '16 at 21:21

3 Answers3

1

Replace below line in your code,

ParseObject testObject = new ParseObject("TestObject");

with,

ParseObject testObject = ParseObject.create("TestObject");

and it will be solved.

Reference

Community
  • 1
  • 1
AAnkit
  • 27,299
  • 12
  • 60
  • 71
0

The error is saying that the ParseObject must be created with its create() method. You have just newed one up without using its factory method. You want something like this:

ParseObject testObject = ParseObject.create("TestObject");
voam
  • 1,006
  • 13
  • 24
  • even after changing problem is still the same – Guneet Kaur Jan 26 '16 at 21:43
  • I would verify that your installation of parse is correct. Maybe double check with what is here: https://www.parse.com/apps/quickstart#parse_data/mobile/android/native/new – voam Jan 26 '16 at 21:59
0

Comment out the following lines an try running again:

//  Parse.enableLocalDatastore(this);
    //        Parse.initialize(this);
      //      ParseObject testObject = new ParseObject("TestObject");
        //    testObject.put("foo", "bar");
//            testObject.saveInBackground();
raddevus
  • 8,142
  • 7
  • 66
  • 87