android加载布局时出现一些错误,但是在运行时没有效果 [英] There's some error when android loading layout,but have no effective on running

查看:410
本文介绍了android加载布局时出现一些错误,但是在运行时没有效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这就是我得到的logcat信息.该应用程序仍然可以运行,但是我想知道出现此错误的原因. 我不明白为什么要得到这个,所以我什至都不知道该怎么问.

So,that's the logcat information I get.The app still can run,but I want to know the reason why I get this error. I don't understand why i get this so i even don't know how to ask.

09-26 07:13:33.510  18533-18533/com.gongxxing.gongxxing0921 D/AccessibilityManager﹕ setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
java.lang.Throwable: setStateLocked
        at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
        at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
        at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
        at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
        at android.view.View.setFlags(View.java:9941)
        at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
        at android.view.ViewGroup.<init>(ViewGroup.java:525)
        at android.view.ViewGroup.<init>(ViewGroup.java:520)
        at android.view.ViewGroup.<init>(ViewGroup.java:516)
        at android.view.ViewGroup.<init>(ViewGroup.java:512)
        at android.widget.FrameLayout.<init>(FrameLayout.java:119)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.<init>(PhoneWindow.java:2341)
        at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3639)
        at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:4026)
        at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:2052)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
        at com.gongxxing.gongxxing0922.MainActivity.onCreate(MainActivity.java:27)
        at android.app.Activity.performCreate(Activity.java:6142)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)


很抱歉忘记粘贴Main活动.


I am sorry for forgetting paste the Main activity.

第27行是

public class MainActivity extends AppCompatActivity  {

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

super.onCreate(savedInstanceState);是第27行.

super.onCreate(savedInstanceState); is the line 27.

推荐答案

很抱歉回答这个老问题,但是我在我的项目中解决了此异常.

Sorry to answer this old question,but i solved this exception in my project.

我认为导致异常的原因是,我们在创建活动时使用的是活动的上下文.

I think what leads to the exception is we are using the context of our activity when it is creating.

我的代码是这样的:

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


private void regToWx(){
    IWXAPI  api;
    api = WXAPIFactory.createWXAPI(this, Constants.WX_APP_ID, true);
    api.registerApp(Constants.WX_APP_ID);
    String text = "123";
    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.scene = SendMessageToWX.Req.WXSceneSession;
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = msg;

    api.sendReq(req);
}

因为regToWx方法需要通过this创建上下文,但是我认为不能(在某些方面)在onCreate方法中使用上下文.所以我只是将其放在线程中,然后问题就解决了.

As the regToWx method need to create something by this which is the context,but i think the context can not be used(in some ways) inside onCreate method. So I just put it in a thread and then the problem is solved.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new Thread(new Runnable() {
        @Override
        public void run() {

            regToWx();
        }
    }).start();

}

因此,尝试找出使用onCreate方法中的context做过的事情,将这些代码放到其中,或者只是使代码异步.

So try to find out what you have done with your context in onCreate method, put these code out of the it or just make the code asynchronous.

这篇关于android加载布局时出现一些错误,但是在运行时没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆