0

请找我。我几乎让它工作了,现在我很头疼!

日志猫:

07-27 11:05:14.565: I/LicenseChecker(24356): Binding to licensing service.
07-27 11:05:14.575: I/LicenseChecker(24356): Calling checkLicense on service for com.liamwli.smsbusy
07-27 11:05:14.580: I/LicenseChecker(24356): Start monitoring timeout.
07-27 11:05:14.650: D/libEGL(24356): loaded /system/lib/egl/libEGL_mali.so
07-27 11:05:14.655: D/libEGL(24356): loaded /system/lib/egl/libGLESv1_CM_mali.so
07-27 11:05:14.655: D/libEGL(24356): loaded /system/lib/egl/libGLESv2_mali.so
07-27 11:05:14.660: D/(24356): Device driver API match
07-27 11:05:14.660: D/(24356): Device driver API version: 10
07-27 11:05:14.660: D/(24356): User space API version: 10 
07-27 11:05:14.660: D/(24356): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Mon Mar  5 09:47:55 KST 2012 
07-27 11:05:14.675: D/OpenGLRenderer(24356): Enabling debug mode 0
07-27 11:05:15.180: I/LicenseChecker(24356): Received response.
07-27 11:05:15.180: I/LicenseChecker(24356): Clearing timeout.
07-27 11:05:15.210: W/dalvikvm(24356): threadid=11: thread exiting with uncaught exception (group=0x40a3c1f8)
07-27 11:05:15.220: E/AndroidRuntime(24356): FATAL EXCEPTION: background thread
07-27 11:05:15.220: E/AndroidRuntime(24356): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4039)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.ViewRootImpl.invalidateChild(ViewRootImpl.java:722)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:771)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.ViewGroup.invalidateChild(ViewGroup.java:4005)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.View.invalidate(View.java:8515)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.widget.TextView.invalidateDrawable(TextView.java:4634)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.graphics.drawable.DrawableContainer.invalidateDrawable(DrawableContainer.java:241)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:350)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.graphics.drawable.Drawable.setVisible(Drawable.java:548)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.graphics.drawable.DrawableContainer.selectDrawable(DrawableContainer.java:298)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.graphics.drawable.StateListDrawable.onStateChange(StateListDrawable.java:106)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.graphics.drawable.Drawable.setState(Drawable.java:464)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.View.drawableStateChanged(View.java:11515)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.widget.TextView.drawableStateChanged(TextView.java:2856)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.View.refreshDrawableState(View.java:11529)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.view.View.setEnabled(View.java:4648)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.widget.TextView.setEnabled(TextView.java:1205)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at com.liamwli.smsbusy.Sms_busyActivity$MyLicenseCheckerCallback.allow(Sms_busyActivity.java:74)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at com.google.android.vending.licensing.LicenseValidator.handleResponse(LicenseValidator.java:211)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:166)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:228)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.os.Handler.handleCallback(Handler.java:605)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.os.Looper.loop(Looper.java:137)
07-27 11:05:15.220: E/AndroidRuntime(24356):    at android.os.HandlerThread.run(HandlerThread.java:60)
07-27 11:05:15.320: D/OpenGLRenderer(24356): Flushing caches (mode 0)
07-27 11:05:15.505: D/OpenGLRenderer(24356): Flushing caches (mode 1)
07-27 11:05:15.515: E/ActivityThread(24356): Activity com.liamwli.smsbusy.Sms_busyActivity has leaked ServiceConnection com.google.android.vending.licensing.LicenseChecker@40e88bf0 that was originally bound here
07-27 11:05:15.515: E/ActivityThread(24356): android.app.ServiceConnectionLeaked: Activity com.liamwli.smsbusy.Sms_busyActivity has leaked ServiceConnection com.google.android.vending.licensing.LicenseChecker@40e88bf0 that was originally bound here
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:936)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:830)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.ContextImpl.bindService(ContextImpl.java:1149)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
07-27 11:05:15.515: E/ActivityThread(24356):    at com.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:150)
07-27 11:05:15.515: E/ActivityThread(24356):    at com.liamwli.smsbusy.Sms_busyActivity.doCheck(Sms_busyActivity.java:61)
07-27 11:05:15.515: E/ActivityThread(24356):    at com.liamwli.smsbusy.Sms_busyActivity.onCreate(Sms_busyActivity.java:55)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.Activity.performCreate(Activity.java:4465)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.ActivityThread.access$600(ActivityThread.java:132)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.os.Looper.loop(Looper.java:137)
07-27 11:05:15.515: E/ActivityThread(24356):    at android.app.ActivityThread.main(ActivityThread.java:4575)
07-27 11:05:15.515: E/ActivityThread(24356):    at java.lang.reflect.Method.invokeNative(Native Method)
07-27 11:05:15.515: E/ActivityThread(24356):    at java.lang.reflect.Method.invoke(Method.java:511)
07-27 11:05:15.515: E/ActivityThread(24356):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-27 11:05:15.515: E/ActivityThread(24356):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-27 11:05:15.515: E/ActivityThread(24356):    at dalvik.system.NativeStart.main(Native Method)
07-27 11:05:17.960: I/Process(24356): Sending signal. PID: 24356 SIG: 9

第 74 行:

allowa.setEnabled(true);

其余的课程:

package com.liamwli.smsbusy;

import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.StrictPolicy;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.Secure;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.content.Intent;

public class Sms_busyActivity extends Activity {

    private LicenseCheckerCallback mLicenseCheckerCallback;
    private LicenseChecker mChecker;
    private Handler mHandler;
    Button allowa;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String android_id = Secure.getString(getBaseContext()
                .getContentResolver(), Secure.ANDROID_ID);

        // if (!android_id.contentEquals("56d330123953677d")) {
        // Log.e("SMS Busy App", "Device ID not allowed. Exiting.");
        // finish();
        // } else {

        // Log.d("SMS Busy App", "Device ID Allowed");
        // }

        // Intent i = new Intent("com.liamwli.smsbusy.PREFS");
        // startActivity(i);

        setContentView(R.layout.def);

        String KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

        mChecker = new LicenseChecker(this, new StrictPolicy(), KEY);

        mLicenseCheckerCallback = new MyLicenseCheckerCallback();

        mHandler = new Handler();

        allowa = (Button) findViewById(R.id.button1);

        doCheck();

    }

    public void doCheck() {

        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow(int reason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.



            allowa.setEnabled(true);
            allowa.setText("App Licensed. Click to continue");

        }

        public void dontAllow(int reason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }

            if (reason == Policy.RETRY) {
                // If the reason received from the policy is RETRY, it was
                // probably
                // due to a loss of connection with the service, so we should
                // give the
                // user a chance to retry. So show a dialog to retry.
                allowa.setText("Retry");

            } else {
                // Otherwise, the user is not licensed to use this app.
                // Your response should always inform the user that the
                // application
                // is not licensed, but your behavior at that point can vary.
                // You might
                // provide the user a limited access version of your app or you
                // can
                // take them to Google Play to purchase the app.
                allowa.setText("INVALID");

            }
        }

        @Override
        public void applicationError(int errorCode) {
            // TODO Auto-generated method stub

        }
    }

}

现在,我知道这可能是一个非常简单的错误,这让我看起来很愚蠢,但请帮助:/

附言

有人能告诉我是什么导致了第二组错误吗?

4

1 回答 1

0

1.当一个应用程序在 Android 上启动时,它在 Dedicated UI thread 上,创建任何其他线程都会让你离开这个 UI 线程。

2.最好让UI工作在UI线程上,Non-UI工作在Non-UI线程上,但自从HoneyComb版本的Android到来后,这成为了一种规律。

3.此错误表示您正在从非 UI 线程修改 UI。

4.使用thread with Handler, 或AsyncTaskAndroid 中专门引入的同步 UI 和 Non-UI 线程。

///////////已编辑///////////

请参阅本教程链接...这将消除您的疑问..

http://www.vogella.com/articles/AndroidPerformance/article.html

于 2012-07-27T10:13:22.777 回答