开发中遇到的错误及解决办法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33197352/article/details/80508186

在Activity中加入Scheme桌面图片不见问题:

在里面在创建一个<inter-filter>属性

<activity
            android:name="com.linghang.app.activity.MainActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden|adjustPan"
            android:configChanges="keyboard|navigation|orientation|keyboardHidden|uiMode|screenSize"
            android:theme="@style/startingTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter >
                <data android:scheme="cfetc"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>

2.viewpager设置不能左右滑动,但是里面的能够滑动解决办法在拦截器和onTouchEvent事件里加一个布尔变量

public class CanScrollViewPager extends ViewPager {
    private boolean isScrollAble=false;
    //防止viewpager滑动左右滑动,但是里面还是可以滑动
    public CanScrollViewPager(@NonNull Context context) {
        this(context, null);
    }

    public CanScrollViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return isScrollAble&&super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return isScrollAble&&super.onTouchEvent(ev);
    }
    
    //解决viewPager里面的recyclerView是水平滑动的时候,防止滑动到最右边或最左边时候viewpager会跟随滑动
    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if (v.getVisibility() != VISIBLE) {
            return false;
        }
        if (v != this && v instanceof RecyclerView
                && ((RecyclerView) v).getLayoutManager() instanceof LinearLayoutManager
                && ((LinearLayoutManager) ((RecyclerView) v).getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) {
            return true;
        }
        return super.canScroll(v, checkV, dx, x, y);
    }
}

3.单例模式:在使用的时候最好在写一个释放方法,防止下次进来时导致上次的实例没有释放,导致初始化数据时候初始化不了

//在使用静态类时,使用完调用这个释放,防止下次进来不会初始化
    public synchronized void release() {
        if (mList != null) {
            mList.clear();
        }
        mList = null;
        mAutoTextMdManager = null;
    }

4.ViewPager+Fragment配合使用的时候会内存泄漏如下图

解决办法在PagerAdapter写一个释放方法给外部调用如图

 

在外部Activity的onDestroy中把vp绑定的Adapter置空如图

 

5.在多次打开同一个Activity中造成多次add一个Fragment也会内存泄漏如下图

解决办法

在ondestroy中写后面两句代码mTransaction.remove(fragment)先移除,在销毁mTransaction.detach(fragment)

 

遇到依赖包冲突的解决办法

1.直接把你的不一致的系列改为和依赖的一致

2.直接删除依赖,重新下载工程下来复制里面的文件在你的工程里面,

3.强行统一版本

在工程build.gradle目录下添加

ext{
    SDK版本 = 28
    编译工具版本 = "$SDK版本.0.3"
    最低兼容版本 = 16
}

subprojects{
    afterEvaluate {
        if(it.hasProperty('android')){
            android {
                compileSdkVersion rootProject.ext.SDK版本
                buildToolsVersion rootProject.ext.编译工具版本

                defaultConfig {
                    minSdkVersion rootProject.ext.最低兼容版本
                    targetSdkVersion rootProject.ext.SDK版本
                }
            }
        }
    }
}

再在项目的build.gradle下添加

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "$rootProject.ext.SDK版本.+"
            }
        }
    }
}

解决android9.0 http不能通信问题,三种解决办法分别如下:

  • APP改用https请求
  • targetSdkVersion 降到27以下
  • 在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml 文件(名字自定) ,内容如下,大概意思就是允许开启http请求
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
   <base-config cleartextTrafficPermitted ="true"/>
</network-security-config>

然后在APP的AndroidManifest.xml文件下的application标签增加以下属性

<application
...
 android:networkSecurityConfig="@xml/network_security_config"
...
/>

GreenDao出现Entity is detached from DAO context 问题解决

直接点击LogCat上面显示错误,看定位到那一行,直接看entity生成greenDao语法如下

其实已经很明确的告诉你是什么问题了,不要看它抛出异常的注释直接看if(choiceOptionList==null)这一句就知道答案,就是服务器返回给你的choiceOptionList是一个null导致的问题,解决办法直接叫后台不要返回一个null的choiceOptionList数组,要么返回空数组,要么返回有数据的数组,或者是你自己本地保存数据赋值的时候不要把choiceOptionList设置null,直接赋值一个空数组,或者有数据的数组,就能解决问题。

开发中遇到More than one file was found with OS independent path 'lib/arm64-v8a/libc++_shared.so'

解决办法在app的目录的build.gralde中添加以下代码把后面的so替换为你的重复的so库就行,意思是如果出现多个so库只优先保留第一个so

packagingOptions{
    pickFirst 'lib/arm64-v8a/libc++_shared.so'
    pickFirst 'lib/x86_64/libc++_shared.so'
    pickFirst 'lib/x86/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
展开阅读全文

MyEclipse+hibernate3开发遇到java.lang.ExceptionInInitializerError的错误

07-11

看了一下Java API,应该是初始化的时候,哪儿有问题,但是又查不出来。rnrn错误提示全文如下:rnjava.lang.ExceptionInInitializerErrorrnall.HibUtil.(HibUtil.java:27)rncom.mytest.struts.action.AdduserAction.execute(AdduserAction.java:49)rnorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rnorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rnorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rnorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:743)rnjavax.servlet.http.HttpServlet.service(HttpServlet.java:856)rnrnrn源代码如下:rnpackage all;rnrnimport org.apache.commons.logging.Log;rnimport org.apache.commons.logging.LogFactory;rnrn//import org.hibernate.*;rn//import org.hibernate.cfg.*;rnimport org.hibernate.Session;rnimport org.hibernate.cfg.Configuration;rnrnimport org.hibernate.HibernateException;rnimport org.hibernate.SessionFactory;rnrnrnrnpublic class HibUtil rn rn private static Log log=LogFactory.getLog(HibUtil.class);rn rn private static final SessionFactory sessionFactory;rn rn static rn tryrn sessionFactory = new Configuration().configure().buildSessionFactory(); rn catch (Throwable ex) rn log.error("Initial SessionFactory creation failed.",ex);rn throw new ExceptionInInitializerError(ex);rn rn rn rn public static final ThreadLocal session=new ThreadLocal();rn rn public static Session currentSession() throws HibernateException rn Session s=(Session)session.get();rn //Open a new Session, if this Thread has none yetrn if (s==null) rn s=sessionFactory.openSession();rn session.set(s);rn rn return s;rn rn rn public static void closeSession() throws HibernateException rn Session s=(Session) session.get();rn session.set(null);rn if (s !=null)rn s.close();rn rnrnrn对应源代码27行处是throw new ExceptionInInitializerError(ex);rnrnAddAction的源代码如下:rn//Created by MyEclipse Strutsrn// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.9.210/xslt/JavaClass.xslrnrnpackage com.mytest.struts.action;rnrnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnimport org.apache.struts.action.Action;rnimport org.apache.struts.action.ActionForm;rnimport org.apache.struts.action.ActionForward;rnimport org.apache.struts.action.ActionMapping;rnrnimport org.hibernate.Session;rnimport org.hibernate.Transaction;rnrnimport all.HibUtil;rnrnimport com.mytest.Hibernate.TmsTrainingHistory;rnrn/** rn * MyEclipse Strutsrn * Creation date: 07-08-2005rn * rn * XDoclet definition:rn * @struts:action validate="true"rn */rnpublic class AdduserAction extends Action rnrn // --------------------------------------------------------- Instance Variablesrnrn // --------------------------------------------------------- Methodsrnrn /** rn * Method executern * @param mappingrn * @param formrn * @param requestrn * @param responsern * @return ActionForwardrn */rn public ActionForward execute(rn ActionMapping mapping,rn ActionForm form,rn HttpServletRequest request,rn HttpServletResponse response) rnrn // TODO Auto-generated method stubrn Session session=HibUtil.currentSession();rn Transaction tx=session.beginTransaction();rn TmsTrainingHistory ulist=new TmsTrainingHistory(); rn ulist.setGid("323926");rn ulist.setSite("237");rn rn session.save(ulist);rn tx.commit();rn HibUtil.closeSession();rn rn return mapping.findForward("/MyTest.jsp");rn rnrnrnrn请高人指点!!!!rnrnrnrn 论坛

Myeclipse开发Struts遇到错误

01-21

我用myeclipse实验《JSP开发应用详解》上ch17的struts简单应用。rnrn我的环境:rn rnjdk 1.5 rnEclipse 3.1(已汉化)rnmyeclipse 4.1.1 GArn书上stuts应用应该是1.1的rntomcat 5.5rnrn我配置完struts-config.xml 在server.xml设置了数据库源,开启Sql Server 2000 。rnrn--------------------------------------------------------------rn但在将项目文件拖入ch17这个项目时候出现错误,随后jsp文件什么的都打不开了:rnrn由于发生内部错误而无法创建此部件。产生该故障的原因是:An error has occurred when initializing the input for the the editor's source page.rnrnAn error has occurred when initializing the input for the the editor's source page.rn at com.genuitec.eclipse.webdesigner2.HTMLMultiPageEditorPart.createPages(HTMLMultiPageEditorPart.java:275)rn at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:241)rnrn..........................................................(省略)rnrn在Eclipse里“问题”中这样写的:rnrnRun-time exception java.lang.InternalError occurred during validation. The validator being run was JSP Validator and the message thrown was jzentry == 0,rn jzfile = 79651040,rn total = 389,rn name = d:\workspace\ch17\WebRoot\WEB-INF\lib\standard.jar,rn i = 78,rn message = invalid LOC header (bad signature).rnrn-----------------------------------------------------------------rnrn我在实验JSTL项目的时候也发生过类似错误,实在搞不懂,望高人指教! 论坛

没有更多推荐了,返回首页