Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There's some error when android loading layout,but have no effective on running

Tags:

android

layout

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)

I am sorry for forgetting paste the Main activity.

The line 27 is

public class MainActivity extends AppCompatActivity  {

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

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

like image 929
yzlee Avatar asked Sep 25 '15 23:09

yzlee


2 Answers

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.

My code is something like:

@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);
}

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();

}

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.

like image 128
tianwei Avatar answered Nov 07 '22 21:11

tianwei


I was getting the same error. I found out that it is due to the attribute android:sharedUserId="com.something" that I was using in the manifest files.

Suppose version 1 of your application has android:sharedUserId in the manifest and initialises a ContentProvider.

Now, suppose in version 2, you remove the android:sharedUserId from the manifest and try to access the ContentProvider created in version 1.

In this case, the recent version will not be able to access the ContentProvider created in version 1.

like image 27
Vaibhav Avatar answered Nov 07 '22 20:11

Vaibhav