在我的应用程序中,我想将幻灯片图片视为带有文本视图的选框(在这里放置图像而不是文本视图),我已经从互联网上获取此代码,但在运行时我有一个运行时间“无法实例化活动组件信息”的异常 我尝试通过右键单击项目然后转到属性然后在java构建路径做一些事情来解决问题,然后清理项目但我仍然有同样的问题,我已经重新启动模拟器和eclipse但是这对我来说对运行这段代码必须做些什么没有用?
这是我的代码:
package com.example.marquee;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
public class AutoSlider extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
int[] IMAGE_IDS = {R.drawable.ic_launcher, R.drawable.yt, R.drawable.yt,
R.drawable.s};
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000; // delay for 1 sec.
int period = 8000; // repeat every 4 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
public void onClick(View v) {
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
private void AnimateandSlideShow() {
slidingimage = (ImageView)findViewById(R.id.imageView1);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
}}
和这个logcat:
07-29 15:21:03.790:W / Trace(1473):来自nativeGetEnabledTags的意外值:0 07-29 15:21:03.842:W / Trace(1473):来自nativeGetEnabledTags的意外值:0 07-29 15:21:03.842:D / AndroidRuntime(1473):关闭VM 07-29 15:21:03.890:W / dalvikvm(1473):threadid = 1:线程退出未捕获异常(组= 0x40a70930) 07-29 15:21:03.980:E / AndroidRuntime(1473):致命异常:主要 07-29 15:21:03.980:E / AndroidRuntime(1473):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.example.marquee / com.example.marquee.MainActivity}:java.lang.ClassNotFoundException:Didn在路径上找不到类“com.example.marquee.MainActivity”:/ data / app / com.example.marquee-1.apk 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.ActivityThread.access $ 600(ActivityThread.java:141) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.os.Handler.dispatchMessage(Handler.java:99) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.os.Looper.loop(Looper.java:137) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.ActivityThread.main(ActivityThread.java:5039) 07-29 15:21:03.980:E / AndroidRuntime(1473):at java.lang.reflect.Method.invokeNative(Native Method) 07-29 15:21:03.980:E / AndroidRuntime(1473):at java.lang.reflect.Method.invoke(Method.java:511) 07-29 15:21:03.980:E / AndroidRuntime(1473):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793) 07-29 15:21:03.980:E / AndroidRuntime(1473):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-29 15:21:03.980:E / AndroidRuntime(1473):at dalvik.system.NativeStart.main(Native Method) 07-29 15:21:03.980:E / AndroidRuntime(1473):引起:java.lang.ClassNotFoundException:在路径上找不到类“com.example.marquee.MainActivity”:/ data / app / com.example .marquee-1.apk 07-29 15:21:03.980:E / AndroidRuntime(1473):at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65) 07-29 15:21:03.980:E / AndroidRuntime(1473):at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 07-29 15:21:03.980:E / AndroidRuntime(1473):at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.Instrumentation.newActivity(Instrumentation.java:1054) 07-29 15:21:03.980:E / AndroidRuntime(1473):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) 07-29 15:21:03.980:E / AndroidRuntime(1473):... 11 more