2015-07-10 27 views
-1

這裏是我的我的signupactivity &主要活動和他們的XML應用程序崩潰

  public class SignupActivity extends AppCompatActivity { 
       protected EditText mUsername; 
       protected EditText mPassword; 
       protected EditText mEmail; 
       protected Button nbutton; 
       @Override 
       protected void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.activity_signup); 
       mUsername = (EditText) findViewById(R.id.usernamefield); 
       mPassword = (EditText) findViewById(R.id.passwordtextfield); 
       mEmail = (EditText) findViewById(R.id.emailtextfield); 
       nbutton = (Button) findViewById(R.id.signbutton); 
       nbutton.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View view){ 
         // Retrieve the text entered from the EditText 
         String usernametxt = mUsername.getText().toString(); 
         String password = mPassword.getText().toString(); 
         String email= mEmail.getText().toString(); 
         // Force user to fill up the form 
         if (usernametxt.equals("") && password.equals("")) { 
          Toast.makeText(getApplicationContext(), 
            "Please complete the sign up form", 
            Toast.LENGTH_LONG).show(); 

         } else { 
          // Save new user data into Parse.com Data Storage 

          ParseUser newUser = new ParseUser(); 
          newUser.setUsername(usernametxt); 
          newUser.setPassword(password); 
          newUser.setEmail(email); 
          newUser.signUpInBackground(new SignUpCallback() { 
           @Override 
           public void done(ParseException e) { 
            //SUCESS 
            if (e!= null){ 

             AlertDialog.Builder builder=new AlertDialog.Builder(SignupActivity.this); 
             builder.setMessage(e.getMessage()).setTitle(R.string.signup_error_title).setPositiveButton(android.R.string.ok, null); 
             AlertDialog dialog = builder.create(); 
             dialog.show(); 
            } 
            else { 


             Intent intent= new Intent(SignupActivity.this,MainActivity.class); 
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
             startActivity(intent); 

            } 
            } 

          }); 
         } 

        } 
       }); 

      } 

有人想獲得ABT用戶的信息,並轉到主要活動從signupactivity.the應用程序崩潰時它獲得來自用戶和按標誌放於...

這裏是XML

<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.josephvarkey996gmail.test1.SignupActivity" > 

     <TextView android:text="@string/hello_world" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/usernamefield" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginTop="89dp" 
      android:hint="@string/username_hint"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="textPassword" 
      android:ems="10" 
      android:id="@+id/passwordtextfield" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@+id/usernamefield" 
      android:hint="@string/password_hint"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="textEmailAddress" 
      android:ems="10" 
      android:id="@+id/emailtextfield" 
      android:hint="@string/email_hint" 
      android:layout_below="@+id/passwordtextfield" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/signup_hint" 
      android:id="@+id/signbutton" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" /> 
    </RelativeLayout> 

    here is the main activity code 

     package com.josephvarkey996gmail.test1; 

     import android.content.Intent; 
     import android.os.Bundle; 
     import android.support.v7.app.AppCompatActivity; 
     import android.util.Log; 
     import android.view.Menu; 
     import android.view.MenuItem; 

     import com.parse.Parse; 
     import com.parse.ParseAnalytics; 
     import com.parse.ParseUser; 

     public class MainActivity extends AppCompatActivity { 

      public static final String TAG = MainActivity.class.getSimpleName(); 

      protected void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.activity_main); 
       Parse.enableLocalDatastore(this); 
       Parse.initialize(this, "XFigOgliUYKi9h5RanLfLkuKU14AG2f2NFQXADKI", "sMQBPkhZV5b74MEGpP3PdQ6eePWo5Y9O8lRcQvBP"); 
       ParseAnalytics.trackAppOpenedInBackground(getIntent()); 


       ParseUser currentUser = ParseUser.getCurrentUser(); 
       if(currentUser==null) { 
        navigatetologin(); 
       } 
       if(currentUser!=null) 
       { 
        Log.i(TAG ,currentUser.getUsername()); 
       } 
       // Enable Local Datastore. 


      } 

      @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; 
      } 



      private void navigatetologin() { 
       Intent intent = new Intent(this, LoginActivity.class); 
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
       startActivity(intent); 
      } 
     } 

mainactivity XML

 <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=".MainActivity" > 

      <TextView android:text="@string/hello_world" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </RelativeLayout> 

Android清單

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

     <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/Theme.AppCompat" > 
      <activity 
       android:name=".MainActivity" 
       android:label="@string/app_name" > 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
      </activity> 
      <activity 
       android:name=".SignupActivity" 
       android:label="@string/title_activity_signup" > 
      </activity> 
      <activity 
       android:name=".LoginActivity" 
        android:label="@string/title_activity_login" > 
       </activity> 
      </application> 
     </manifest> 
+0

是的,我們得到了那 – Chaosit

+0

你可以發佈你的異常logcat嗎? – Chaosit

+2

post logcat info .. –

回答

0

我們不能幫你直到你發表您的logcat的。由於我沒有足夠的評論聲望,我正在寫這個答案。

最常見的原因,我看到人們正在此錯誤是: 他們複製 - 粘貼該行從另一個類

R.id.usernamefield 

所以它會嘗試運行他們的其他類的usernamefield中不存在這裏(注意:eclipse會自動導入,所以他們沒有得到編譯錯誤)。所以要解決你的錯誤,你應該刪除導入並寫入正確的R.id.xyz

但是這只是在黑暗中拍攝,直到我們看到你的logcat。