2017-04-03 60 views
0

Logcat image我正在使用我的Web應用程序端點來創建本機登錄android應用程序。但在嘗試登錄時,我可以在控制檯日誌中看到登錄成功的結果。但我希望該活動重定向到其他活動。下面我張貼我的通過Android模擬器成功登錄後應用程序崩潰

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
    <manifest 
    xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.example.reception.farbinder_test"> 
<uses-permission android:name="android.permission.INTERNET"/> 
<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=".MainActivity"> 
      <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 

      <category 
      android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
      </activity> 
      <activity android:name=".ResponseActivity"></activity> 
       <activity android:name=".SettingsActivity"></activity> 
       </application> 
       </manifest> 

mainactivity.java

   public class MainActivity extends AppCompatActivity 
       implements 
       View.OnClickListener { 

       private List<String> stringList; 
      private ListView list; 
      private LoginPOJO jsonResponse; 
      EditText etUserName; 
      EditText etPassword; 
      ImageView btnLogin; 


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

      jsonResponse = new LoginPOJO(); 

      // UserLogin Field 
      etUserName = (EditText) findViewById(R.id.etUserName); 
      // UserLogin Password 
      etPassword = (EditText) findViewById(R.id.etPassword); 
      // Login Button Image 
      btnLogin = (ImageView) findViewById(R.id.btnLogin); 
      btnLogin.setOnClickListener(this); 
      // User SignUp Button Image 
      ImageView btnSignUp = (ImageView) 
      findViewById(R.id.btnSignUp); 
      btnSignUp.setOnClickListener(this); 
      // Forget Password Textbutton 
      TextView frgtPassword = (TextView) 
      findViewById(R.id.forgetpassword); 
      frgtPassword.setOnClickListener(this); 
      // Skip for now button 
      final TextView skipfornow = (TextView) 
       findViewById(R.id.skipnow); 
      skipfornow.setOnClickListener(this); 

      } 

       private void 
      logIn(final String username, final String password) 
       { 
      final ProgressDialog progressDialog = new 
      ProgressDialog(MainActivity.this); 
      progressDialog. 
      setProgressStyle(ProgressDialog.STYLE_SPINNER); 
      progressDialog.setMessage("Logging you in..."); 
      progressDialog.setIndeterminate(true); 
      progressDialog.setCancelable(false); 
      progressDialog.show(); 
      String UPLOAD_URL = "http://xxxxx- 
      dev.elasticbeanstalk.com/api/v1/login"; 
      final StringRequest stringRequest = new 
      StringRequest(Request.Method.POST, UPLOAD_URL, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String s) { 
        //Dismissing the progress dialog 
        progressDialog.dismiss(); 
        // Getting the final Json Object 
        JSONObject parentObject; 
        try { 
         parentObject = new JSONObject(s); 

         // Getting the data from Data Json Object 
         JSONObject dataObject = 
       parentObject.getJSONObject("data"); 

         // Getting data from Geo object 
         JSONObject geoObject = 
       dataObject.getJSONObject("geo"); 

         // Getting data from businesses Array 
         JSONArray businessesArray = 
       dataObject.getJSONArray("businesses"); 

         // Getting data from Meta Object 
         JSONObject metaObject = 
       parentObject.getJSONObject("meta"); 

         startActivity(new Intent(MainActivity.this, 
       ResponseActivity.class)); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
        //Showing toast message of the response 
        Log.i("TAG", "onResponse: " + s); 

       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError volleyError) 
       { 
        //Dismissing the progress dialog 
        progressDialog.dismiss(); 
        //Showing snackbar 
        Toast.makeText(MainActivity.this, "Connection 
       Problem", Toast.LENGTH_SHORT).show(); 
       } 
      }) { 
      @Override 
      protected Map<String, String> getParams() throws 
      AuthFailureError { 
      //Converting Bitmap to String 
      //Creating parameters 
      Map<String, String> params = new Hashtable<>(); 
      params.put("apikey", Utilities.API_KEY); 
      params.put("secret", Utilities.SECRET_KEY); 
      params.put("email", username); 
      params.put("password",password); 
      //Adding parameters 
      //returning parameters 
      return params; 
       } 
       }; 
      //Creating a Request Queue 
      RequestQueue requestQueue =Volley.newRequestQueue(this); 
      //Adding request to the queue 
       requestQueue.add(stringRequest); 
       } 
       private void forgetPassword(final String userName) { 
       final ProgressDialog progressDialog = new 
       ProgressDialog(MainActivity.this); 
       progressDialog.setProgressStyle 
       (ProgressDialog.STYLE_SPINNER); 
       progressDialog.setMessage("Logging you in..."); 
       progressDialog.setIndeterminate(true); 
       progressDialog.setCancelable(false); 
       progressDialog.show(); 
       String UPLOAD_URL = "http://xxxxxx- 
      dev.elasticbeanstalk.com/api/v1/request_password_reset"; 
      final StringRequest stringRequest = new 
       StringRequest(Request.Method.POST, UPLOAD_URL, 
       new Response.Listener<String>() { 
       @Override 
       public void onResponse(String s) { 
        //Dismissing the progress dialog 
        progressDialog.dismiss(); 
        // Getting the final Json Object 
        JSONObject parentObject; 
        try { 
         parentObject = new JSONObject(s); 

         // Getting the data from Data Json Object 
         JSONObject dataObject = 
       parentObject.getJSONObject("data"); 

         // Getting data from Geo object 
         JSONObject geoObject = 
       dataObject.getJSONObject("geo"); 

         // Getting data from businesses Array 
         JSONArray businessesArray = 
       dataObject.getJSONArray("businesses"); 

         // Getting data from Meta Object 
         JSONObject metaObject = 
       parentObject.getJSONObject("meta"); 

         startActivity(new Intent(MainActivity.this, 
       ResponseActivity.class)); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
        //Showing toast message of the response 
        Log.i("TAG", "onResponse: " + s); 

       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError volleyError) 
      { 
        //Dismissing the progress dialog 
        progressDialog.dismiss(); 
        //Showing snackbar 
        Toast.makeText(MainActivity.this, "Connection 
      Problem", Toast.LENGTH_SHORT).show(); 
       } 
      }) { 
      @Override 
      protected Map<String, String> getParams() throws 
      AuthFailureError { 
      //Converting Bitmap to String 
      //Creating parameters 
      Map<String, String> params = new Hashtable<>(); 
      params.put("apikey", Utilities.API_KEY); 
      params.put("secret", Utilities.SECRET_KEY); 
      params.put("email", userName); 
      //Adding parameters 
      //returning parameters 
      return params; 
      } 
       }; 
      //Creating a Request Queue 
      RequestQueue requestQueue = Volley.newRequestQueue(this); 
      //Adding request to the queue 
      requestQueue.add(stringRequest); 
      } 

      private void signUp() { 

      Intent singUppage = new 
      Intent(MainActivity.this,ResponseActivity.class); 
      startActivity(singUppage); 

      } 
      private void skipForNow(){ 
      Intent skipForNowPage = new 
      Intent(MainActivity.this,ResponseActivity.class); 
      startActivity(skipForNowPage); 
      } 



      @Override 
      public void onClick(View v) { 
      switch (v.getId()) { 
      case R.id.btnLogin: { 
      String username = etUserName.getText().toString().trim(); 
      String password = etPassword.getText().toString().trim(); 
      logIn(username, password); 
      break; 
      } 
      case R.id.forgetpassword: { 
      String username = etUserName.getText().toString().trim(); 
      forgetPassword(username); 
      break; 
      } 
      case R.id.btnSignUp:{ 
      signUp(); 
      break; 
      } 
      case R.id.skipnow:{ 
      skipForNow(); 
      break; 
      } 
      } 
      } 

activitymain.xml

  <?xml version="1.0" encoding="utf-8"?> 
      <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      tools:context="com.example.reception.xxx.MainActivity"> 

      <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="@drawable/signin_bg" 
      android:orientation="vertical" 
      android:paddingEnd="20dp" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp" 
      android:paddingStart="20dp" 
      android:weightSum="1"> 

      <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:contentDescription="@string/farbinder_text" 
      android:src="@drawable/vdsss"/> 

      <ImageView 
      android:id="@+id/facebookSigninButton" 
      android:layout_width="343dp" 
      android:layout_height="76dp" 
      android:contentDescription="@string/connect_with_facebook" 
      android:src="@drawable/signin_fb"/> 

      <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="92dp" 
      android:contentDescription="@string/connect_with_twitter" 
      android:src="@drawable/signin_twitter"/> 

      <ImageView 
      android:id="@+id/btnSignUp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/signup_with_email" 
      android:src="@drawable/signup_button"/> 

      <TextView 
      android:id="@+id/skipnow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="@string/skip_login_for_now" 
      android:textColor="#FFF" 
      android:textSize="16sp"/> 

      </LinearLayout> 

      <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="187dp" 
      android:orientation="vertical" 
      android:paddingLeft="20dp" 
      android:paddingStart="20dp" 
      android:paddingEnd="20dp" 
      android:paddingRight="20dp" 
      android:paddingBottom="5dp"> 

      <EditText 
       android:id="@+id/etUserName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:autoLink="email" 
       android:hint="@string/enter_email" 
       android:inputType="text"/> 

      <EditText 
       android:id="@+id/etPassword" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textPassword" 
       android:hint="@string/enter_password"/> 

       <ImageView 
       android:id="@+id/btnLogin" 
       android:layout_width="match_parent" 
       android:layout_height="63dp" 
      android:contentDescription="@string/sign_in" 
       android:src="@drawable/signin_button"/> 

       <TextView 
       android:id="@+id/forgetpassword" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/forgot_password" 
       android:textSize="16sp" 
       android:layout_gravity="center_horizontal"/> 

       </LinearLayout> 

      </LinearLayout> 

activityresponse.xml

  <?xml version="1.0" encoding="utf-8"?> 
      <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:padding="16dp"  
      tools:context= 
      "com.example.reception.xxxx.MainActivity"> 
      <TextView 
      android:id="@+id/tvStatus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:layout_gravity="center_horizontal"/> 
      <ImageView 
      android:id="@+id/backArrow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="center" 
      android:src="@drawable/backarrow" 
      android:contentDescription="@string/backarrow" 
     /> 
     <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="240dp" 
     android:scaleType="centerCrop"/> 
     <Button 
      android:id="@+id/btnSelectImage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/select_image" 
      android:textAllCaps="false" 
      android:layout_gravity="center_horizontal"/> 
      </LinearLayout> 

responseactivity.java

  public class ResponseActivity extends AppCompatActivity 
      implements 
      View.OnClickListener { 
      private final int IMAGE_REQUEST_CODE = 5; 
      private ImageView ivImage; 
      private Bitmap selectedImage; 
      @Override 
      protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_response); 
      TextView tvResponse = (TextView) 
      findViewById(R.id.tvStatus); 
      ivImage = (ImageView) findViewById(R.id.image); 
      ImageView etSignUp = (ImageView) 
      findViewById(R.id.btnSignUp); 
      etSignUp.setOnClickListener(this); 
      ImageView backArrow = 
      (ImageView)findViewById(R.id.backArrow); 
      backArrow.setOnClickListener(this); 
      } 
      private void backArrow(){ 
      Intent bckArrow = new 
      Intent(ResponseActivity.this,MainActivity.class); 
      startActivity(bckArrow); 
      } 
      private void signUp(){ 
      Intent signUp = new 
      Intent(ResponseActivity.this,SettingsActivity.class); 
      startActivity(signUp); 
      } 

      @Override 
      public void onClick(View v) { 
      switch (v.getId()) { 
      case R.id.backArrow:{ 
      backArrow(); 
      break; 
      } 
      case R.id.btnSignUp:{ 
      signUp(); 
      break; 
      } 

      } 
      } 
+0

一個nullpointerException張貼logcat的錯誤... – rafsanahmad007

+0

你好,我剛剛發佈的logcat的圖像可以請你幫我解決這@ rafsanahmad007 – Arun

回答

0

問題是在這裏:

ImageView etSignUp = (ImageView)findViewById(R.id.btnSignUp); 
etSignUp.setOnClickListener(this); 

你沒有ID爲btnSignUp一個imageview的在你的ResponseActivity佈局。

這就是爲什麼它給人的imageview

+0

非常感謝你..問題已解決 – Arun