对于我的活动,我创建了一个新视图并将其保存在公共静态字段中。然后我在活动中使用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));
活动已添加到清单中,可以启动。
任何帮助将不胜感激
答案 0 :(得分:0)
您的LockActivity
存在问题。确保已在清单文件中添加该条目。
答案 1 :(得分:0)
context.findViewById();
上下文是您的活动,或者您可以尝试
View view = (View) =LayoutInflater.from(activity.this).inflate(your layout,null)