Android运行时间除外:致命异常:主要

时间:2015-11-04 11:46:19

标签: java android android-layout android-intent

我使用自定义ActionBar进行导航,例如A - > B - > c,c - > B - >一个。 在应用程序导航A - > B - > c单击C到 - >>正常工作B,妈妈我得到运行时异常。我的logCat添加贝娄.......

............. SublistBrowserCatalog .class ................

public class SublistBrowserCatalog extends Activity{
    ArrayAdapter<String> adapter;
    private String name,title;
    private DatabaseHelper dbHeplper;
    private ListView lvUsers;
    private List<JSONObject> listItem;
    static Bundle resStr;
    private static List<JSONObject> list_info;
    // public String Hose_Name;
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.browse_catalog);
        Log.v("BrowserCatalog", "BrowserCatalog");
        resStr = getIntent().getExtras();
        name = resStr.getString("bhh", null);
        title = resStr.getString("name", null);
        //getActionBar().setTitle(name);
        System.out.println(".....................>>"+title);
        ActionBar mActionBar = getActionBar();
        mActionBar.setDisplayShowHomeEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(false);
        LayoutInflater mInflater = LayoutInflater.from(this);

        View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
        TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
        mTitleTextView.setText(title);
        ImageButton imageB = (ImageButton) mCustomView
                .findViewById(R.id.backb);
        imageB.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {


                Intent i = new Intent(getApplicationContext(), BrokerSubList.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(i);

            }
        });

        ImageButton imageButton = (ImageButton) mCustomView
                .findViewById(R.id.imageButton);
        imageButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {

                Intent i = new Intent(getApplicationContext(), MainActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(i);
            }
        });

        mActionBar.setCustomView(mCustomView);
        mActionBar.setDisplayShowCustomEnabled(true);


        list_info = new ArrayList<JSONObject>();
        dbHeplper = new DatabaseHelper(getApplicationContext());
        try {
            dbHeplper.createDataBase();
        } catch (IOException e) {
            e.printStackTrace();
        }

        lvUsers = (ListView)findViewById(R.id.pr_enginslist);
        listItem = dbHeplper.getAllData();

        for(int j=0;j<listItem.size();j++){ 
            try {
                //Log.v("DDD", Boolean.toString((listItem.get(j).get("type").toString().toLowerCase().replace(" ", "")).contains(name.toLowerCase().replace(" ", ""))));
                if(listItem.get(j).get("type").toString().toLowerCase().trim().equalsIgnoreCase(name.toLowerCase().trim())){
                    //Log.v("DDD", listItem.get(j).get("type").toString());
                    list_info.add(listItem.get(j));
                }

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

        lvUsers.setAdapter(new EfficientAdapter(this));

    }

    private static class EfficientAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private Context context;
        public EfficientAdapter(Context context) {
            this.context = context;
            mInflater = LayoutInflater.from(context);
        }

        public int getCount() {
            return SublistBrowserCatalog.list_info.size();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }


        static class ViewHolder {
            TextView text1;
            TextView text2;
            ImageView hoses;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup arg2) {
             ViewHolder holder;
                if (convertView == null) {
                    convertView = mInflater.inflate(R.layout.customview_item, null);
                    holder = new ViewHolder();
                    holder.text1 = (TextView) convertView .findViewById(R.id.pr_name);
                    holder.text2 = (TextView)convertView.findViewById(R.id.sample_text);
                    holder.hoses = (ImageView)convertView.findViewById(R.id.icon);
                    convertView.setTag(holder);

                } else {
                    holder = (ViewHolder) convertView.getTag();
                }
                    try {
                        holder.text1.setText(list_info.get(position).get("product").toString());
                        holder.text2.setText(list_info.get(position).get("name").toString());

                        InputStream open = context.getAssets().open("Hoses_Images/"+list_info.get(position).get("i_name").toString());
                        System.out.println(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"+list_info.get(position).get("i_name").toString());
                        Bitmap bitmap = BitmapFactory.decodeStream(open);
                        holder.hoses.setImageBitmap(bitmap);
                        holder.hoses.setTag(list_info.get(position));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }


                convertView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent pk_web = new Intent(context, SublistParkerwebView.class);
                        pk_web.putExtra("viewObj", list_info.get(position).toString());
                        pk_web.putExtra("bc", "Browseatalog");
                        pk_web.putExtra("name", resStr.getString("name", null));
                        pk_web.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                        context.startActivity(pk_web);
                    }
                });

                return convertView;
        }
    }
}

............. SublistParkerwebView.class ..................

public class SublistParkerwebView extends Activity{
    JSONObject pkObj;
    JSONObject oneJB;
    WebView mWebView = null;
    Button SendIt;
    String Title,ramu,title;
    String Hoses = "file:///android_asset/Hoses_Images/";
    String FilePath;
    private String email_subject;
    File file,newDir,files,newDirs;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.pk_webview);

        Button pk_webBt = (Button) findViewById(R.id.pk_webBt);
        SendIt = (Button) findViewById(R.id.sendto);
        Intent intent = getIntent();
        Bundle resStr = getIntent().getExtras();
        title = resStr.getString("name", null);
        ramu = resStr.getString("bc", null);

        ActionBar mActionBar = getActionBar();
        mActionBar.setDisplayShowHomeEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(false);
        LayoutInflater mInflater = LayoutInflater.from(this);

        View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
        TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
        mTitleTextView.setText(title);

        ImageButton imageB = (ImageButton) mCustomView.findViewById(R.id.backb);
        imageB.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {

                if (ramu.toString().equals("Browseatalog")) {
                    Toast.makeText(getApplicationContext(), "IH", Toast.LENGTH_LONG).show();
                Intent i = new Intent(getApplicationContext(), StampCatalog.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);


                }else  {
                    Toast.makeText(getApplicationContext(), "sublist", Toast.LENGTH_LONG).show();
                }
            }
        });




        ImageButton imageButton = (ImageButton) mCustomView
                .findViewById(R.id.imageButton);
        imageButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {

                Intent i = new Intent(getApplicationContext(), MainActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(i);
            }
        });
        mActionBar.setCustomView(mCustomView);
        mActionBar.setDisplayShowCustomEnabled(true);

        try {
            Log.v("get string from another class", intent.getStringExtra("viewObj"));
            pkObj = new JSONObject(intent.getStringExtra("viewObj"));
            System.out.println("pkObj =====>"+pkObj);
            Title = pkObj.getString("name");
            System.out.println("Title =====>"+Title);
            Log.d("OutPut", pkObj.getString("name"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            pkObj = new JSONObject(intent.getStringExtra("viewObj"));

            String string = "file:///android_asset/Hoses_Images/hyd_"+pkObj.getString("i_desc").toString();
            Log.v("URL  =====================", string);

            try{
                InputStream open = getAssets().open("Hoses_Images/hyd_"+pkObj.getString("i_desc"));
                Bitmap bitmp = BitmapFactory.decodeStream(open);
                String root = Environment.getExternalStorageDirectory().toString();
                newDirs = new File(root + "/Parker");  
                if(!newDirs.exists())
                    newDirs.mkdirs();

                String pn = "details.png";
                files = new File (newDirs, pn);
                if (files.exists ()) files.delete ();
                FileOutputStream rm = new FileOutputStream(files);

                bitmp.compress(Bitmap.CompressFormat.JPEG, 90, rm);
                rm.flush();
                rm.close();
                bitmp.recycle();

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

        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            if (pkObj.getString("eqpVal") != null) {
                pk_webBt.setVisibility(ImageButton.GONE);
            }
        } catch (JSONException e1) {
            e1.printStackTrace();
        }
        mWebView = (WebView) findViewById(R.id.pk_webId);
        mWebView.getSettings().setJavaScriptEnabled(true);
        try {
            mWebView.loadUrl(Hoses + pkObj.getString("f_name").toString());
            Log.d("ImagePath", Hoses + pkObj.getString("i_name").toString());
            FilePath = Hoses + pkObj.getString("i_name").toString();
            try {

                InputStream is = getAssets().open("Hoses_Images/"+pkObj.getString("f_name"));
                int size = is.available();
                byte[] buffer = new byte[size];
                is.read(buffer);
                is.close();
                email_subject = new String(buffer);
                InputStream open = getAssets().open("Hoses_Images/"+pkObj.getString("i_name"));
                Bitmap bitmap = BitmapFactory.decodeStream(open);

                String root = Environment.getExternalStorageDirectory().toString();
                newDir = new File(root + "/Parker");  
                if(!newDir.exists())
                    newDir.mkdirs();

                String fotoname = "Photo.png";
                file = new File (newDir, fotoname);
                if (file.exists ()) file.delete ();
                FileOutputStream out = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
                out.flush();
                out.close();
                bitmap.recycle();
            } catch (Exception e) {
                e.printStackTrace();
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        pk_webBt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent pk_web = new Intent(getApplicationContext(),
                        ParkerTiff.class);
                try {
                    pk_web.putExtra("webObj", pkObj.getString("i_desc")
                            .toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                startActivity(pk_web);
            }
        });

        SendIt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE, Uri.fromParts("mailto","", null));
                emailIntent.setType("image/png");
                emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Parker");
                emailIntent.putExtra(Intent.EXTRA_TEXT,  Html.fromHtml(email_subject));
                emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

                ArrayList<Uri> uris = new ArrayList<Uri>();
                String[] filePaths = new String[] {"sdcard/Parker/Photo.png", "sdcard/Parker/details.png"};
                System.out.println("filePaths =====>"+filePaths);
                for (String file : filePaths)
                {
                    File fileIn = new File(file);
                    Uri u = Uri.fromFile(fileIn);
                    uris.add(u);
                }
                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                startActivity(Intent.createChooser(emailIntent,"Send"));
                try {
                     startActivity(Intent.createChooser(emailIntent, "Choose an email client from..."));

                } catch (android.content.ActivityNotFoundException ex) {
               }
            }
            });
}

}

..............我的logCat ....................

11-05 01:21:52.993: V/BrowserCatalog(7529): BrowserCatalog
11-05 01:21:52.993: D/AndroidRuntime(7529): Shutting down VM
11-05 01:21:52.993: W/dalvikvm(7529): threadid=1: thread exiting with uncaught exception (group=0x55da4b20)
11-05 01:21:52.993: I/Process(7529): Sending signal. PID: 7529 SIG: 9
11-05 01:21:52.993: D/AndroidRuntime(7529): procName from cmdline: com.parker
11-05 01:21:52.993: E/AndroidRuntime(7529): in writeCrashedAppName, pkgName :com.parker
11-05 01:21:52.993: D/AndroidRuntime(7529): file written successfully with content: com.parker StringBuffer : ;com.parker
11-05 01:21:52.993: E/AndroidRuntime(7529): FATAL EXCEPTION: main
11-05 01:21:52.993: E/AndroidRuntime(7529): Process: com.parker, PID: 7529
11-05 01:21:52.993: E/AndroidRuntime(7529): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parker/com.parker.SublistBrowserCatalog}: java.lang.NullPointerException
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.os.Handler.dispatchMessage(Handler.java:102)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.os.Looper.loop(Looper.java:136)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.ActivityThread.main(ActivityThread.java:5021)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at java.lang.reflect.Method.invokeNative(Native Method)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at java.lang.reflect.Method.invoke(Method.java:515)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at dalvik.system.NativeStart.main(Native Method)
11-05 01:21:52.993: E/AndroidRuntime(7529): Caused by: java.lang.NullPointerException
11-05 01:21:52.993: E/AndroidRuntime(7529):     at com.parker.SublistBrowserCatalog.onCreate(SublistBrowserCatalog.java:59)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.Activity.performCreate(Activity.java:5231)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
11-05 01:21:52.993: E/AndroidRuntime(7529):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-05 01:21:52.993: E/AndroidRuntime(7529):     ... 11 more

1 个答案:

答案 0 :(得分:0)

你得到这个,因为你在com.parker.Dummy.onCreate(Dummy.java:44)得到NullPointerException。