2 u010443946 u010443946 于 2013.11.20 19:38 提问

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个回答

songzhiyong1121
songzhiyong1121   2013.11.28 13:55
已采纳

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!