u010443946 2013-11-20 11:38 采纳率: 100%
浏览 2641
已采纳

android 类qq空间图片查看器。出现好多错误 求大神帮忙。小女涉入甚浅。

11-20 11:26:39.629: E/AndroidRuntime(1136): FATAL EXCEPTION: main
11-20 11:26:39.629: E/AndroidRuntime(1136): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.desktop/com.example.desktop.ImageShowActivity}: java.lang.InstantiationException: can't instantiate class com.example.desktop.ImageShowActivity
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.os.Looper.loop(Looper.java:137)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-20 11:26:39.629: E/AndroidRuntime(1136): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 11:26:39.629: E/AndroidRuntime(1136): at java.lang.reflect.Method.invoke(Method.java:511)
11-20 11:26:39.629: E/AndroidRuntime(1136): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-20 11:26:39.629: E/AndroidRuntime(1136): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-20 11:26:39.629: E/AndroidRuntime(1136): at dalvik.system.NativeStart.main(Native Method)
11-20 11:26:39.629: E/AndroidRuntime(1136): Caused by: java.lang.InstantiationException: can't instantiate class com.example.desktop.ImageShowActivity
11-20 11:26:39.629: E/AndroidRuntime(1136): at java.lang.Class.newInstanceImpl(Native Method)
11-20 11:26:39.629: E/AndroidRuntime(1136): at java.lang.Class.newInstance(Class.java:1319)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
11-20 11:26:39.629: E/AndroidRuntime(1136): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
11-20 11:26:39.629: E/AndroidRuntime(1136): ... 11 more

出错代码
package com.example.desktop;
//import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.SpinnerAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ViewSwitcher.ViewFactory;
import android.widget.AdapterView;

public abstract class ImageShowActivity extends Activity implements OnItemSelectedListener,ViewFactory
{
private Gallery g ;
private ImageSwitcher mSwitcher=null;
private Integer[] mThumberIDs={
R.drawable.xx,
R.drawable.wang,
R.drawable.dh,
R.drawable.zm
};
private Context mcontext;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE) ;
setContentView(R.layout.image_show);
setTitle("ImageShowActivity");
mSwitcher = (ImageSwitcher) findViewById(R.id.swit);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
g = (Gallery) findViewById(R.id.gall);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);

}
public View makeView()
{
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new android.view.ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
return i;
}

public class ImageAdapter extends BaseAdapter{
public ImageAdapter (Context c)
{
mcontext = c;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return  mThumberIDs.length;
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
    // TODO Auto-generated method stub
    return null;
}

}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mcontext);
i.setImageResource(mThumberIDs[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.zm);
return i;
}

}

  • 写回答

1条回答

  • Jerome_Song 2013-11-28 05:55
    关注

    你的Activity是抽象的,肯定不能启动。建议使用 其具体实现类,或者把abstract去掉并实现相应方法

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名