使用Intent时,活动意外停止

时间:2013-05-14 14:10:36

标签: android android-intent fatal-error

你好stackoverflowers我是新的蜜蜂到android。任何人都可以帮助我逃避致命的错误。

05-14 19:32:49.552: E/AndroidRuntime(1657): FATAL EXCEPTION: main
05-14 19:32:49.552: E/AndroidRuntime(1657): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.DJ.HOLYHERB/com.DJ.HOLYHERB.Prd_list}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.os.Looper.loop(Looper.java:123)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.ActivityThread.main(ActivityThread.java:3647)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at java.lang.reflect.Method.invoke(Method.java:507)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at dalvik.system.NativeStart.main(Native Method)
05-14 19:32:49.552: E/AndroidRuntime(1657): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.Activity.setContentView(Activity.java:1657)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at com.xyz.My_list.onCreate(My_list.java:429)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
05-14 19:32:49.552: E/AndroidRuntime(1657):     ... 11 more
05-14 19:32:49.552: E/AndroidRuntime(1657): Caused by: java.lang.reflect.InvocationTargetException
05-14 19:32:49.552: E/AndroidRuntime(1657):     at java.lang.reflect.Constructor.constructNative(Native Method)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
05-14 19:32:49.552: E/AndroidRuntime(1657):     ... 21 more
05-14 19:32:49.552: E/AndroidRuntime(1657): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.Bitmap.nativeCreate(Native Method)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:463)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.View.<init>(View.java:1951)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.View.<init>(View.java:1899)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.view.ViewGroup.<init>(ViewGroup.java:286)
05-14 19:32:49.552: E/AndroidRuntime(1657):     at android.widget.LinearLayout.<init>(LinearLayout.java:120)
05-14 19:32:49.552: E/AndroidRuntime(1657):     ... 24 more
05-14 19:32:52.442: I/Process(1657): Sending signal. PID: 1657 SIG: 9

以及从其中抛出exeption的“登录表单”如下所示::

package com.xyz.ACCOUNT;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.xyz.My_list;
import com.xyz.R;

public class SignInActivity extends Activity {

    EditText email,pwd;
    TextView err_tv;
    Intent i;
    Context c;
       @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.signin);
            c=getApplicationContext();
            email=(EditText)findViewById(R.id.email);
            pwd=(EditText)findViewById(R.id.pwd);
            err_tv=(TextView)findViewById(R.id.info_text);
        }
       public void goto_signUp(View v){
           i=new Intent(this,SignUpActivity.class);
            startActivity(i);
       }
       public void goto_forgotPwd(View v){
           i=new Intent(this,ForgotPwdActivity.class);
            startActivity(i);
       }
        public void action_signIn(View v){
            try{    
                signin l=new signin(this);
                l.execute(email.getText().toString(), pwd.getText().toString());
            }catch (Exception e) {
                msg = "Err-"+e.getLocalizedMessage();
                showDialog(DIALOG_ERR_MESSAGE);
            }
        }

        class signin extends AsyncTask<String, Void, Boolean> {
            // String message;
            ProgressDialog mProgressDialog;
            boolean isSuccess;

            private Activity activity;

            public signin(Activity activity) {
                this.activity = activity;
            }

            Resources res = getResources();
            String httpConnStr = res.getString(R.string.httpConnStr);

            protected void onPreExecute() { mProgressDialog =
             ProgressDialog.show(SignInActivity.this, "Please wait...",
             "Authenticating..."); }

            @Override
            protected void onPostExecute(Boolean result) {
                // TODO Auto-generated method stub
                super.onPostExecute(result);
                mProgressDialog.cancel();
                if(result){
                //  Toast.makeText(SignInActivity.this, "Welcome :: "+user_id+"::"+user_fname,
                //          Toast.LENGTH_LONG).show();
                //  msg = "Welcome - "+user_id+"::"+user_fname;
                //  showDialog(DIALOG_ERR_MESSAGE);
                    Toast.makeText(activity, Boolean.toString(result), Toast.LENGTH_LONG).show();
                    activity.startActivity(new Intent(activity, My_list.class));
                }else{
                    err_tv.setText("Invalid EmailId/Password");
                    msg = "Invalid EmailId/Password";
                    showDialog(DIALOG_ERR_MESSAGE);
                }
            }
            @Override
            protected Boolean doInBackground(String... params) {
                // TODO Auto-generated method stub
                String email = params[0];
                String pwd = params[1];
                return isSuccess = getServerData(httpConnStr,email,pwd);
            }
        }
        String user_id="0",user_fname="#";
        private boolean getServerData(String CONN_KEY,String email, String pwd) {
            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("query", "signIn"));
            postParameters.add(new BasicNameValuePair("email", email));
            postParameters.add(new BasicNameValuePair("pwd", pwd));
            String response = null;
            try {
                response = com.DJ.HOLYHERB.CONN.CustomHttpClient.executeHttpPost(
                        CONN_KEY, postParameters);
                String result = response.toString();
                if(result.equals("")){
                    return false;
                }else{
                    try {
                        JSONArray jArray = new JSONArray(result);
                        JSONObject json_data = jArray.getJSONObject(0);

                        user_id = json_data.getString("user_id");
                        user_fname = json_data.getString("user_fname");

                    } catch (Exception e) {
                        Log.e("log_tag", "Error parsing data " + e.toString());
                        msg = "Error parsing data " + e.toString();
                        showDialog(DIALOG_ERR_MESSAGE);
                        return false;
                    }       
                }
            } catch (Exception e) {
                Log.e("log_tag", "Error in http connection!!" + e.toString());

                msg = "Error in http connection!!" + e.toString();
                msg = "Error in Connection.\nDo check ur connection & try Again.";
                showDialog(DIALOG_ERR_MESSAGE);
                return false;
            }
            return true;
        }
        private static final int DIALOG_ERR_MESSAGE = 1;
        private static final int DIALOG_PROGRESS = 4;
        private static final int MAX_PROGRESS = 100;
        private ProgressDialog mProgressDialog;
        String msg = "-", title = "ERROR...";

        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DIALOG_ERR_MESSAGE:
                return new AlertDialog.Builder(this)
                        .setIcon(R.drawable.alert_dialog_icon)
                        .setTitle(title)
                        .setMessage(msg)
                        .setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int whichButton) {

                                        // User clicked Cancel so do some stuff
                                    }
                                }).create();
            case DIALOG_PROGRESS:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
                mProgressDialog.setTitle(title);
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setMax(MAX_PROGRESS);
                mProgressDialog.setButton("hide",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                            }
                        });
                mProgressDialog.setButton2("cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                            }
                        });
                return mProgressDialog;
            }
            return null;
        }
}

2 个答案:

答案 0 :(得分:2)

您是否在例外中注意到了这一点:

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

我认为这是一个内存不足的问题。

答案 1 :(得分:1)

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

尝试使用 bitmap.recycle() 回收您正在使用的位图并将它们设置为空

您还可以缩放/调整大小您的位图,以确保它占用的空间最小。