私のアクティビティでは、新しいビューを作成し、パブリック静的フィールドに保存しました。次に、アクティビティでsetContentViewを使用してビューを設定します。ただし、別のクラスからビューの色を変更しようとすると、次のような例外が発生します。
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.TwinBlade.PicturePassword/com.TwinBlade.PicturePassword.LockActivity}: java.lang.ClassNotFoundException: com.TwinBlade.PicturePassword.LockActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.TwinBlade.PicturePassword.LockActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
... 11 more
java.lang.ClassNotFoundException: com.TwinBlade.PicturePassword.LockActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
アップデート:
これが私の活動でしたことです
public static View mView;
public void onCreate(Bundle savedInstanceState) {
mView = new LinearLayout(this);
mView.setBackgroundColor(Color.argb(0, 0, 0, 0));
setContentView(mView);
}
そして、別のクラスからビューの色を変更するには:
LockActivity.mView.setBackgroundColor(Color.argb(255, 0, 0, 0));
アクティビティはマニフェストに追加され、起動できます。
どんな助けでもいただければ幸いです