工作Android应用程序变得不稳定

时间:2015-04-30 02:10:07

标签: android performance android-layout android-intent android-activity

我创建了一个Android应用程序,它具有添加配置文件和编辑它的功能。所有这些日子里一切都运转正常,但是在我编辑个人资料后我每次尝试保存更改时都突然今天上午,它开始停止响应并退出。

我使用崩溃邮件捕获了错误,这是我得到的:

USER_COMMENT=null
ANDROID_VERSION=4.4.2
APP_VERSION_NAME=1.0
BRAND=samsung
PHONE_MODEL=SHV-E300L
CUSTOM_DATA=
STACK_TRACE=java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.<init>(Uri.java:467)
at android.net.Uri$StringUri.<init>(Uri.java:457)
at android.net.Uri.parse(Uri.java:429)
at com.diwesh.Ecgapp.adapter.AdapterProfileList.getView(AdapterProfileList.java:78)
at android.widget.AbsListView.obtainView(AbsListView.java:2720)
at android.widget.ListView.makeAndAddView(ListView.java:1801)
at android.widget.ListView.fillDown(ListView.java:697)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1627)
at android.widget.AbsListView.onLayout(AbsListView.java:2533)
at android.view.View.layout(View.java:15656)
at android.view.ViewGroup.layout(ViewGroup.java:4857)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:15656)
at android.view.ViewGroup.layout(ViewGroup.java:4857)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15656)
at android.view.ViewGroup.layout(ViewGroup.java:4857)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15656)
at android.view.ViewGroup.layout(ViewGroup.java:4857)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15656)
at android.view.ViewGroup.layout(ViewGroup.java:4857)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2288)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2008)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1238)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6473)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

AdapterList.java

package com.diwesh.Ecgapp.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diwesh.Ecgapp.R;
import com.diwesh.Ecgapp.db.ProfileDBManager.ProfileModel;
import com.diwesh.Ecgapp.doc.Globals;
import com.pkmmte.circularimageview.CircularImageView;


public class AdapterProfileList extends BaseAdapter {

    public List<ProfileModel> m_lstItems;    
    public int selItem = -1;
    public Context con;
//    private SwipeDetector swipeDetector;

    public AdapterProfileList(Context con)
    {
        super();
        this.con = con;
//        swipeDetector = new SwipeDetector();
    }
    public int getCount()
    {
        if (this.m_lstItems == null)
            return 0;
        return this.m_lstItems.size();
    }

    public ProfileModel getItem(int paramInt)
    {
        return this.m_lstItems.get(paramInt);
    }

    public long getItemId(int paramInt)
    {
        return 0L;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
        View localView = paramView;
        ViewHolder localViewHolder = null;

        if (localView == null)
        {
            localView = LayoutInflater.from(paramViewGroup.getContext()).inflate(R.layout.item_profile, null);
        }
        else
        {
            localViewHolder = (ViewHolder) localView.getTag();
        }
        if (localViewHolder == null){
            localViewHolder = new ViewHolder();
            localViewHolder.m_item1 = ((CircularImageView)localView.findViewById(R.id.imgDoge));
            localViewHolder.m_item2 = ((TextView)localView.findViewById(R.id.txt_profile_item)); 
            localViewHolder.ll_swipe = ((LinearLayout)localView.findViewById(R.id.ll_profile));

            localView.setTag(localViewHolder);
        }

//        localViewHolder.ll_swipe.setOnTouchListener(swipeDetector);
        //add String
        final ProfileModel t = m_lstItems.get(paramInt);
        //localViewHolder.m_item1.setImageURI(Uri.parse(t.image));
        Bitmap bm = Globals.setImageScale(con, Uri.parse(t.image));
        localViewHolder.m_item1.setImageBitmap(bm);        
        String ss = t.firstName +  " " + t.lastName + " " + t.age +"years old";
        if (t.gender == 0)
        {
            ss = ss + " Male";
        }
        else
        {
            ss = ss + " Female";
        }
        localViewHolder.m_item2.setText(ss);    


        return localView;
    }

    public void update(List<ProfileModel> paramList)
    {
        this.m_lstItems = paramList;
        notifyDataSetChanged();
    }

    public class ViewHolder
    {
        public CircularImageView m_item1;
        public TextView m_item2;      
        public LinearLayout ll_swipe;
    }

    public void remove(int id) {
        // TODO Auto-generated method stub
        Log.e("LIST ITEMSL::", ""+m_lstItems);
        Log.e("mLIST ITEM SIZE::"+m_lstItems.size(), "ID>>>>"+id);
        m_lstItems.remove(m_lstItems.get(id));
        notifyDataSetChanged();
    }



}

请帮助.....

编辑1:按照建议添加了空检查:应用程序在重新启动时不会立即崩溃,但在再次编辑后再单击“配置文件”选项卡时仍然会崩溃。这是新的logcat

USER_COMMENT=null
ANDROID_VERSION=4.4.2
APP_VERSION_NAME=1.0
BRAND=samsung
PHONE_MODEL=SHV-E300L
CUSTOM_DATA=
STACK_TRACE=java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.<init>(Uri.java:467)
at android.net.Uri$StringUri.<init>(Uri.java:457)
at android.net.Uri.parse(Uri.java:429)
at com.diwesh.Ecgapp.ui.Fragment3.setData(Fragment3.java:149)
at com.diwesh.Ecgapp.ui.Fragment3.initControl(Fragment3.java:142)
at com.diwesh.Ecgapp.ui.Fragment3.onCreateView(Fragment3.java:75)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

更改后的新AdapterList.java

package com.diwesh.Ecgapp.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diwesh.Ecgapp.R;
import com.diwesh.Ecgapp.db.ProfileDBManager.ProfileModel;
import com.diwesh.Ecgapp.doc.Globals;
import com.pkmmte.circularimageview.CircularImageView;


public class AdapterProfileList extends BaseAdapter {

    public List<ProfileModel> m_lstItems;    
    public int selItem = -1;
    public Context con;
//    private SwipeDetector swipeDetector;

    public AdapterProfileList(Context con)
    {
        super();
        this.con = con;
//        swipeDetector = new SwipeDetector();
    }
    public int getCount()
    {
        if (this.m_lstItems == null)
            return 0;
        return this.m_lstItems.size();
    }

    public ProfileModel getItem(int paramInt)
    {
        return this.m_lstItems.get(paramInt);
    }

    public long getItemId(int paramInt)
    {
        return 0L;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
        View localView = paramView;
        ViewHolder localViewHolder = null;

        if (localView == null)
        {
            localView = LayoutInflater.from(paramViewGroup.getContext()).inflate(R.layout.item_profile, null);
        }
        else
        {
            localViewHolder = (ViewHolder) localView.getTag();
        }
        if (localViewHolder == null){
            localViewHolder = new ViewHolder();
            localViewHolder.m_item1 = ((CircularImageView)localView.findViewById(R.id.imgDoge));
            localViewHolder.m_item2 = ((TextView)localView.findViewById(R.id.txt_profile_item)); 
            localViewHolder.ll_swipe = ((LinearLayout)localView.findViewById(R.id.ll_profile));

            localView.setTag(localViewHolder);
        }

//        localViewHolder.ll_swipe.setOnTouchListener(swipeDetector);
        //add String
        final ProfileModel t = m_lstItems.get(paramInt);
        //localViewHolder.m_item1.setImageURI(Uri.parse(t.image));

        if(t.image != null) // added this to prevent crash mail
        {
        Bitmap bm = Globals.setImageScale(con, Uri.parse(t.image));
        localViewHolder.m_item1.setImageBitmap(bm);     
        }
        String ss = t.firstName +  " " + t.lastName + " " + t.age +"years old";
        if (t.gender == 0)
        {
            ss = ss + " Male";
        }
        else
        {
            ss = ss + " Female";
        }
        localViewHolder.m_item2.setText(ss);    


        return localView;
    }

    public void update(List<ProfileModel> paramList)
    {
        this.m_lstItems = paramList;
        notifyDataSetChanged();
    }

    public class ViewHolder
    {
        public CircularImageView m_item1;
        public TextView m_item2;      
        public LinearLayout ll_swipe;
    }

    public void remove(int id) {
        // TODO Auto-generated method stub
        Log.e("LIST ITEMSL::", ""+m_lstItems);
        Log.e("mLIST ITEM SIZE::"+m_lstItems.size(), "ID>>>>"+id);
        m_lstItems.remove(m_lstItems.get(id));
        notifyDataSetChanged();
    }



}

3 个答案:

答案 0 :(得分:0)

根据您的堆栈跟踪,您将获得一个null uriString(显然)。

只要有可能存在空值,就应该有一个空检查器。

如果没有关于您的问题的进一步信息,我们可以向您推荐这一切。

答案 1 :(得分:0)

在此错误情况下,您的图片URI即将出现<meta>。为了预防,我们可以添加Null检查:

null

这将解决上述致命错误

答案 2 :(得分:0)

从您的日志中,t.image为空,因此导致错误。在调用Uri.parse()之前,您应该检查它是否为空。

至于为什么它发生在今天而不是昨天,有太多的可能性:也许你已经清除了数据,也许你已经更新了一些你忘了你已经更新过的代码,也许数据已经搞砸了你的其他部分应用程序。请专注于跟踪代码,而不是“为什么它今天不起作用”。