从Android Studio运行时应用程序运行正常,但安装签名apk时崩溃

时间:2016-09-21 11:03:45

标签: java android

我有一个应用程序从PHP文件中提取数据,然后解析JSON返回并将数据放入列表中。在通过USB插入的手机上从Android工作室运行应用程序时,该应用程序100%正常工作。但是,当我构建应用程序的签名版本时,该活动不再有效。因此应用程序打开,我可以在搜索字段中输入一个数字,但是当我点击运行该活动的提交时,应用程序崩溃。

活动代码:

    package com.*.*;

    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;

    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;

    import java.util.ArrayList;
    import java.util.HashMap;

    public class ViewBalances extends AppCompatActivity {
        private String TAG = ViewBalances.class.getSimpleName();

        private ProgressDialog pDialog;
        private ListView lv;

        ArrayList<HashMap<String, String>> contactList;

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

            contactList = new ArrayList<>();

            lv = (ListView) findViewById(R.id.list);

            new GetContacts().execute();
        }

        /**
         * Async task class to get json by making HTTP call
         */
        private class GetContacts extends AsyncTask<Void, Void, Void> {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Showing progress dialog
                pDialog = new ProgressDialog(ViewBalances.this);
                pDialog.setMessage("Please wait...");
                pDialog.setCancelable(false);
                pDialog.show();

            }

            @Override
            protected Void doInBackground(Void... arg0) {
                HttpHandler sh = new HttpHandler();

                Intent inte = getIntent();
                String memnum = inte.getExtras().getString("membernumber_input");

                // Making a request to url and getting response
                String url = "****";
                String jsonStr = sh.makeServiceCall(url +memnum);

                Log.e(TAG, "Response from url: " + jsonStr);

                if (jsonStr != null) {
                    try {
                        JSONObject jsonObj = new JSONObject(jsonStr);

                        // Getting JSON Array node
                        JSONArray contacts = jsonObj.getJSONArray("contacts");

                        // looping through All Contacts
                        for (int i = 0; i < contacts.length(); i++) {
                            JSONObject c = contacts.getJSONObject(i);

                            String Savings_Amount = c.getString("Savings_Amount");
                            String name = c.getString("name");
                            String member_number = c.getString("member_number");
                            String phone_office = c.getString("phone_office");

                            // tmp hash map for single contact
                            HashMap<String, String> contact = new HashMap<>();

                            // adding each child node to HashMap key => value
                            contact.put("Savings_Amount", Savings_Amount);
                            contact.put("name", name);
                            contact.put("CellNo", phone_office);
                            contact.put("member_number", member_number);

                            // adding contact to contact list
                            contactList.add(contact);
                        }
                    } catch (final JSONException e) {
                        Log.e(TAG, "Json parsing error: " + e.getMessage());
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),
                                        "Json parsing error: " + e.getMessage(),
                                        Toast.LENGTH_LONG)
                                        .show();
                            }
                        });

                    }
                } else {
                    Log.e(TAG, "Couldn't get json from server.");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "Couldn't get json from server. Check LogCat for possible errors!",
                                    Toast.LENGTH_LONG)
                                    .show();
                        }
                    });

                }

                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                // Dismiss the progress dialog
                if (pDialog.isShowing())
                    pDialog.dismiss();
                /**
                 * Updating parsed JSON data into ListView
                 * */
                ListAdapter adapter = new SimpleAdapter(
                        ViewBalances.this, contactList,
                        R.layout.list_item, new String[]{"name", "Savings_Amount", "member_number", "CellNo"}, new int[]{R.id.name, R.id.Savings_Amount, R.id.member_number, R.id.CellNo});

                lv.setAdapter(adapter);
            }

        }
    }

希望有人可以帮助我......?请?

错误:

    09-21 13:20:41.814 13880-13880/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                       Process: com.caliber.caliberclinicalconsultants, PID: 13880
                                                       java.lang.IllegalStateException: Could not find method ViewBalResult(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'submit'
                                                           at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:321)
                                                           at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:280)
                                                           at android.view.View.performClick(View.java:5697)
                                                           at android.widget.TextView.performClick(TextView.java:10826)
                                                           at android.view.View$PerformClick.run(View.java:22526)
                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                           at android.os.Looper.loop(Looper.java:158)
                                                           at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
    09-21 13:20:41.824 776-1626/? W/ActivityManager:   Force finishing activity com.caliber.caliberclinicalconsultants/.MainActivity

2 个答案:

答案 0 :(得分:1)

在大多数情况下,原因是Proguard。 你必须检查你使用的proguard文件和类。

答案 1 :(得分:1)

使用以下代码更新您的Proguard文件。

public Bitmap savebit(){

        Bitmap  saveBitmap = Bitmap.createBitmap(this.getWidth(), this.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(saveBitmap);
        canvas.setBitmap(saveBitmap);
        this.draw(canvas);

        File file = new File(Environment.getExternalStorageDirectory() + "/sign.jpg");

        try {
            saveBitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return saveBitmap;
    }