了解Eclipse IDE中的Log Cat错误

时间:2013-03-07 18:57:26

标签: java php android json parsing

我正在制作一个Android应用程序,每次我尝试运行我的应用程序时都会出现一些错误。

我已经阅读了一些关于Java中Null Pointer Exceptions的资料,但实际上无法实现任何解决方案。

似乎我的代码中存在一个我需要纠正的错误。

供您参考,我在日志中收到以下错误:

03-07 18:42:27.562: W/dalvikvm(631): threadid=1: thread exiting with uncaught exception (group=0x40014760)
03-07 18:42:27.582: E/AndroidRuntime(631): FATAL EXCEPTION: main
03-07 18:42:27.582: E/AndroidRuntime(631): java.lang.NullPointerException
03-07 18:42:27.582: E/AndroidRuntime(631):  at com.fokrul.justdeals.ActivityTab$BooksAdapter.getView(ActivityTab.java:1453)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.AbsListView.obtainView(AbsListView.java:1970)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.ListView.makeAndAddView(ListView.java:1756)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.ListView.fillDown(ListView.java:656)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.ListView.fillFromTop(ListView.java:716)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.ListView.layoutChildren(ListView.java:1595)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.AbsListView.onLayout(AbsListView.java:1800)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.FrameLayout.onLayout(FrameLayout.java:400)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1542)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1403)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1314)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.FrameLayout.onLayout(FrameLayout.java:400)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.FrameLayout.onLayout(FrameLayout.java:400)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1542)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1403)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1314)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.widget.FrameLayout.onLayout(FrameLayout.java:400)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.View.layout(View.java:9581)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewGroup.layout(ViewGroup.java:3877)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1282)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.view.ViewRoot.handleMessage(ViewRoot.java:2040)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.os.Looper.loop(Looper.java:132)
03-07 18:42:27.582: E/AndroidRuntime(631):  at android.app.ActivityThread.main(ActivityThread.java:4123)
03-07 18:42:27.582: E/AndroidRuntime(631):  at java.lang.reflect.Method.invokeNative(Native Method)
03-07 18:42:27.582: E/AndroidRuntime(631):  at java.lang.reflect.Method.invoke(Method.java:491)
03-07 18:42:27.582: E/AndroidRuntime(631):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-07 18:42:27.582: E/AndroidRuntime(631):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-07 18:42:27.582: E/AndroidRuntime(631):  at dalvik.system.NativeStart.main(Native Method)

我无法弄清楚真正的问题是什么!任何想法这些错误可能指向什么?

我们非常感谢您的帮助。提前谢谢。

编辑:1 ACTIVITYTAB.JAVA

// to get a View that displays the data at the specified position in the data set. 
        public View getView(int position, View convertView, ViewGroup parent) {
            PromotionsHolder holder; 
            if(convertView == null){
                convertView = inflater.inflate(R.layout.item_product, null);
                holder = new PromotionsHolder();
                holder.imgImage = (ImageView)convertView.findViewById(R.id.imgImage);
                holder.imgImage.getLayoutParams().height = 80;
                holder.imgImage.getLayoutParams().width = 80;
                holder.tvName = (TextView)convertView.findViewById(R.id.tvName);
                holder.tvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
                holder.tvPrice = (TextView)convertView.findViewById(R.id.tvPrice);
                convertView.setTag(holder);
            }else{
                holder = (PromotionsHolder)convertView.getTag();
            }
            Bitmap bmp = BitmapFactory.decodeFile(soImage.get(position));
            holder.imgImage.setImageBitmap(bmp);
            holder.tvTitle.setText(soTitle.get(position));
            ((TextView) holder.tvCode).setText(soCode.get(position));
            holder.tvPrice.setText(soPrice.get(position));

            return convertView;
        }
    }

    private static class ProductsHolder{
        ImageView imgImage;
        TextView tvCode, tvPrice, tvTitle;
    }

    private class BooksAdapter extends BaseAdapter{
        private LayoutInflater inflater;
        private ArrayList<String> list;

        public BooksAdapter(ArrayList<String> ll){
            inflater = (LayoutInflater)ActivityTab.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            list = ll;
        }

        //number of items in the data set are linked by this Adapter.
        public int getCount() {
            return list.size();
        }

        // to get data item associated with the specified position in the data set.
        public Object getItem(int position) {
            return list.get(position);
        }

        // to get the row id associated with the specified position in the list.
        public long getItemId(int position) {
            return position;
        }

        // to get a View that displays the data at the specified position in the data set.
        public View getView(int position, View convertView, ViewGroup parent) {
            ProductsHolder holder; 
            if(convertView == null){
                convertView = inflater.inflate(R.layout.item_product, null);
                holder = new ProductsHolder();
                holder.imgImage = (ImageView)convertView.findViewById(R.id.imgImage);
                holder.imgImage.getLayoutParams().height = 80;
                holder.imgImage.getLayoutParams().width = 80;
                holder.tvCode = (TextView)convertView.findViewById(R.id.tvCode);
                holder.tvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
                holder.tvPrice = (TextView)convertView.findViewById(R.id.tvPrice);
                convertView.setTag(holder);
            }else{
                holder = (ProductsHolder)convertView.getTag();
            }
            Bitmap bmp = BitmapFactory.decodeFile(bImage.get(position));
            holder.imgImage.setImageBitmap(bmp);
            holder.tvTitle.setText(bTitle.get(position)); <----Line 1453
            holder.tvCode.setText(bCode.get(position));    
            holder.tvPrice.setText(bPrice.get(position));

            return convertView;
        }
    }

1 个答案:

答案 0 :(得分:0)

  

NullPointerException的原因

当任何对象包含null并且您尝试访问它时会发生。

对于前。

String str = null;
Log.v("App",str);

检查ActivityTab.java:1453。在这种情况下,它出现在这一行上。