2014-04-16 89 views
1

我一直在創建一個應用程序來記錄和註冊用戶,在使用一個asynctask,但認爲我做到了這一點。請參閱下面的錯誤消息和代碼Android操作時崩潰

04-16 11:27:17.160: D/AndroidRuntime(31658): Shutting down VM 
04-16 11:27:17.160: W/dalvikvm(31658): threadid=1: thread exiting with uncaught exception (group=0x41c4c700) 
04-16 11:27:17.175: E/AndroidRuntime(31658): FATAL EXCEPTION: main 
04-16 11:27:17.175: E/AndroidRuntime(31658): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.applicationnfclogin/com.applicationnfclogin.DashboardActivity}: android.view.InflateException: Binary XML file line #92: Error inflating class progressbar 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.ActivityThread.access$700(ActivityThread.java:159) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.os.Looper.loop(Looper.java:176) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.ActivityThread.main(ActivityThread.java:5419) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at java.lang.reflect.Method.invokeNative(Native Method) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at java.lang.reflect.Method.invoke(Method.java:525) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at dalvik.system.NativeStart.main(Native Method) 
04-16 11:27:17.175: E/AndroidRuntime(31658): Caused by: android.view.InflateException: Binary XML file line #92: Error inflating class progressbar 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.Activity.setContentView(Activity.java:1956) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at com.applicationnfclogin.DashboardActivity.onCreate(DashboardActivity.java:23) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.Activity.performCreate(Activity.java:5372) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257) 
04-16 11:27:17.175: E/AndroidRuntime(31658): ... 11 more 
04-16 11:27:17.175: E/AndroidRuntime(31658): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.progressbar" on path: /data/app/com.applicationnfclogin-1.apk 
04-16 11:27:17.175: E/AndroidRuntime(31658): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.createView(LayoutInflater.java:565) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:658) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) 
04-16 11:27:17.175: E/AndroidRuntime(31658): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) 
04-16 11:27:17.175: E/AndroidRuntime(31658): ... 21 more 
04-16 11:27:37.400: D/AndroidRuntime(32009): Shutting down VM 
04-16 11:27:37.400: W/dalvikvm(32009): threadid=1: thread exiting with uncaught exception (group=0x41c4c700) 

(我知道它的雷區) 請參閱下面的登錄頁面代碼:

import java.io.BufferedReader; 
import java.io.InputStream; 
import java.io.InputStreamReader; 

import org.apache.http.HttpResponse; 
import org.json.JSONException; 
import org.json.JSONObject; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ProgressBar; 
import android.widget.TextView; 
import com.applicationnfclogin.R; 
import android.widget.TextView; 

import com.applicationnfclogin.internal.DatabaseHandler; 
import com.applicationnfclogin.internal.JSONParser; 
import com.applicationnfclogin.internal.NFCHandler; 

import com.applicationnfclogin.internal.UserFunctions; 
import android.app.ProgressDialog; 


public class LoginActivity extends Activity{ 

private 

//NfcAdapter Nfc; 
Button btnLogin; 
Button btnNfcScan; 
Button btnLinkToRegister; 
EditText inputUsername; 
EditText inputPassword; 
TextView loginErrorMsg; 
ProgressDialog pDialog; 
JSONParser jsonParser = new JSONParser(); 
private ProgressBar progress; 
private ProgressBar progress2; 
private TextView text; 
// JSON Response node names 
private static String KEY_SUCCESS = "success"; 
private static String KEY_ERROR = "error"; 
private static String KEY_ERROR_MSG = "error_msg"; 
private static String KEY_UID = "uid"; 
private static String KEY_FIRSTNAME = "Firstname"; 
private static String KEY_LASTNAME = "Lasrname"; 
private static String KEY_USERNAME = "Username"; 
private static String KEY_PASSWORD = "password"; 
private static String KEY_EMAIL = "email"; 
private static String KEY_CREATED_AT = "created_at "; 


@Override 
public void onCreate (Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 
    progress = (ProgressBar) findViewById(R.id.progressBar1); 
    progress2 = (ProgressBar) findViewById(R.id.progressBar2); 
    text = (TextView) findViewById(R.id.textView1); 
    //Nfc = NfcAdapter.getDefaultAdapter(null); 

    //Importing all assets like buttons, text fields 
    inputUsername = (EditText) findViewById(R.id.loginUsername); 
    inputPassword = (EditText) findViewById(R.id.loginPassword); 
    btnLogin = (Button) findViewById (R.id.btnLogin); 
    btnLinkToRegister = (Button) findViewById (R.id.btnLinkToRegisterScreen); 
    loginErrorMsg = (TextView) findViewById (R.id.login_error); 

    // Login button Click Event 
    btnLogin.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View view) { 
      //TODO Auto-generated method stub 
      String Username = inputUsername.getText().toString(); 
      String password = inputPassword.getText().toString(); 
      Runnable runnable = new Runnable(){ 
       @Override 
       public void run() { 
        for (int i = 0; i <= 10; i++) { 
         final int value = i; 
         checklogin(); 
         progress.post(new Runnable() { 
          @Override 
          public void run() { 
           text.setText("Loading"); 
           progress.setProgress(value); 
          } 
         }); 
        } 
       } 
      }; 
      new Thread(runnable).start(); 
      LoggingTask task = new LoggingTask(); 
      task.execute(Username, password); 
     } 
     private void checklogin() { 
      try { 
       Thread.sleep(200); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 


     /* 
     * User logged in task 
     */ 
     class LoggingTask extends AsyncTask<String, String, String> { 

      @Override 
      protected String doInBackground(String...params) { 
       UserFunctions userFunctions = new UserFunctions(); 
       JSONParser jParser = new JSONParser(); 
       JSONObject json = userFunctions.loginUser(KEY_USERNAME, KEY_PASSWORD); 

       try{ 
       if (!KEY_USERNAME.equals(KEY_USERNAME) &&!KEY_PASSWORD.equals(KEY_PASSWORD)) { 
          loginErrorMsg.setText(""); 
          String res = json.getString(KEY_SUCCESS); 
          if(Integer.parseInt(res) ==1) { 
           DatabaseHandler db = new DatabaseHandler(getApplicationContext()); 
           JSONObject json_user = json.getJSONObject("user"); 
           db.addUser(json_user.getString(KEY_FIRSTNAME), json_user.getString(KEY_LASTNAME), json_user.getString(KEY_USERNAME), json_user.getString(KEY_UID), json_user.getString(KEY_EMAIL), json_user.getString(KEY_CREATED_AT)); 
           Intent dashboard = new Intent (getApplicationContext(), DashboardActivity.class); 
           dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
           startActivity(dashboard); 
          }else{ loginErrorMsg.setText("Incorrect Username and or Password"); 
          } 
         } 

        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 



         return null; 
        } 
      } 

      });       


    // Link to Register Screen 
    btnLinkToRegister.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
      Runnable runnable = new Runnable(){ 
       @Override 
       public void run() { 
        for (int i = 0; i <= 10; i++) { 
         final int value = i; 
         Register(); 
         progress.post(new Runnable() { 
          @Override 
          public void run() { 
           text.setText("loading"); 
           progress.setProgress(value); 
          } 
         }); 
        } 
       } 
      }; 
      new Thread(runnable).start(); 

     } 
     private void Register() { 
      try { 
       Thread.sleep(2000); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
     { 
      Intent i = new Intent(getApplicationContext(), 
        RegisterActivity.class); 
      startActivity(i); 
      finish(); 


     } 
    }); 



} 

} 

主要頁面(儀表盤):

package com.applicationnfclogin; 


import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.View; 
import android.widget.Button; 
import android.os.AsyncTask; 
import com.applicationnfclogin.R; 
import com.applicationnfclogin.internal.NFCHandler; 
import com.applicationnfclogin.internal.UserFunctions; 

public class DashboardActivity extends Activity { 
UserFunctions userFunctions; 
Button btnLogout; 
Button btnNfcScan; 


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

    btnNfcScan = (Button) findViewById(R.id.btnNfcScan); 



    /**Dashboard Screen for the application * */  
    // Check login status in database 
    userFunctions = new UserFunctions(); 
    CheckLoginTask task = new CheckLoginTask(); 
    task.execute(); 

} 


/* 
* CHeck user logged in task 
*/ 
private class CheckLoginTask extends AsyncTask<Void, Void, Boolean> { 

    @Override 
    protected Boolean doInBackground(Void...nothing) { 
     return userFunctions.isUserLoggedIn(DashboardActivity.this); 
    } 

    @Override 
    protected void onPostExecute(Boolean result) { 
     if(result){ 
      // user already logged in show databoard 
      //setContentView (R.layout.activity_dashboard); 
      btnLogout = (Button) findViewById(R.id.btnLogout); 

      btnLogout.setOnClickListener(new View.OnClickListener() { 

       public void onClick(View argo) { 
        userFunctions.logoutUser(getApplicationContext()); 
        Intent login = new Intent (getApplicationContext(), LoginActivity.class); 

        startActivity(login); 
        finish(); 
       } 



      }); 
     }else{ 
      Intent login = new Intent(getApplicationContext(), LoginActivity.class); 
      login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(login); 
     } 

    // Scan 
    //this button is null and throws the exception 
    //the async task worked fine 
    btnNfcScan.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View argo){ 
      Intent in = new Intent(getApplicationContext(), 
        NFCHandler.class); 
      startActivity(in); 
      finish(); 

     } 
    }); 
    } 

} 
} 

回答