我是一个非常早期的android和java初学者。我在一个简单的Gallery视图中发现了一个非常奇怪的错误。我有7张图片可以滚动。这是奇怪的部分。首次打开应用程序时,只能看到第1张,第2张和第3部分。当我尝试滚动到pic 4及以上(打开模拟器时看不到的那些)时,它给出了一个错误,内容为:Source Not Found。 JAR文件没有源。再次,这只发生如果我尝试滚动到pic3以上的任何内容。这是我的main.xml文件代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".GalleryActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Images of San Francisco" />
<Gallery
android:id="@+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/image1"
android:layout_width="320dp"
android:layout_height="250dp"
android:scaleType="fitXY" />
这是针对attrs.xml的
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>
最后,这是我的java文件。
package net.learn2develop.Gallery;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.view.Menu;
public class GalleryActivity extends Activity {
//---the images to display---
Integer[]imageIDs = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v,
int position, long id)
{
Toast.makeText(getBaseContext(),
"pic" + (position + 1) + " selected",
Toast.LENGTH_SHORT).show();
ImageView imageView =
(ImageView) findViewById(R.id.image1);
imageView.setImageResource(imageIDs[position]);
}
});
}
public class ImageAdapter extends BaseAdapter
{
Context context;
int itemBackground;
public ImageAdapter(Context c)
{
context = c;
//---setting the style---
TypedArray a = obtainStyledAttributes(
R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground,
0);
a.recycle();
}
public int getCount() {
return imageIDs.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setScaleType(
ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(
new Gallery.LayoutParams(150, 120));
} else {
imageView = (ImageView) convertView;
}
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gallery, menu);
return true;
}
}
以下是我的所有Logcat:
05-10 00:21:29.134: E/Trace(769): error opening trace file: No such file or directory (2)
05-10 00:21:29.174: W/ActivityThread(769): Application net.learn2develop.Gallery is waiting for the debugger on port 8100...
05-10 00:21:29.194: I/System.out(769): Sending WAIT chunk
05-10 00:21:29.374: I/dalvikvm(769): Debugger is active
05-10 00:21:29.414: I/System.out(769): Debugger has connected
05-10 00:21:29.414: I/System.out(769): waiting for debugger to settle...
05-10 00:21:29.624: I/System.out(769): waiting for debugger to settle...
05-10 00:21:29.824: I/System.out(769): waiting for debugger to settle...
05-10 00:21:30.054: I/System.out(769): waiting for debugger to settle...
05-10 00:21:30.264: I/System.out(769): waiting for debugger to settle...
05-10 00:21:30.464: I/System.out(769): waiting for debugger to settle...
05-10 00:21:30.664: I/System.out(769): waiting for debugger to settle...
05-10 00:21:30.944: I/System.out(769): waiting for debugger to settle...
05-10 00:21:31.144: I/System.out(769): debugger has settled (1316)
05-10 00:21:32.484: D/dalvikvm(769): GC_FOR_ALLOC freed 71K, 8% free 2515K/2708K, paused 60ms, total 81ms
05-10 00:21:32.535: I/dalvikvm-heap(769): Grow heap (frag case) to 5.571MB for 3145744-byte allocation
05-10 00:21:32.664: D/dalvikvm(769): GC_FOR_ALLOC freed 2K, 4% free 5585K/5784K, paused 131ms, total 131ms
05-10 00:21:32.774: D/dalvikvm(769): GC_CONCURRENT freed <1K, 4% free 5585K/5784K, paused 9ms+4ms, total 107ms
05-10 00:21:33.524: D/dalvikvm(769): GC_FOR_ALLOC freed <1K, 4% free 5584K/5784K, paused 233ms, total 234ms
05-10 00:21:33.724: I/dalvikvm-heap(769): Grow heap (frag case) to 12.319MB for 7077904-byte allocation
05-10 00:21:33.814: D/dalvikvm(769): GC_CONCURRENT freed 0K, 2% free 12496K/12700K, paused 20ms+16ms, total 87ms
05-10 00:21:34.524: D/libEGL(769): loaded /system/lib/egl/libEGL_emulation.so
05-10 00:21:34.524: D/(769): HostConnection::get() New Host Connection established 0x2a173820, tid 769
05-10 00:21:34.618: D/libEGL(769): loaded /system/lib/egl/libGLESv1_CM_emulation.so
05-10 00:21:34.624: D/libEGL(769): loaded /system/lib/egl/libGLESv2_emulation.so
05-10 00:21:34.804:W / EGL_emulation(769):eglSurfaceAttrib未实现 05-10 00:21:29.489:D / OpenGLRenderer(769):启用调试模式0 05-10 00:21:29.839:D / dalvikvm(769):GC_FOR_ALLOC释放3073K,26%免费9763K / 13040K,暂停84ms,总计179ms 05-10 00:21:29.849:I / dalvikvm-heap(769):将堆(frag case)增长到12.650MB,用于3145744字节分配 05-10 00:21:29.991:D / dalvikvm(769):GC_CONCURRENT释放&lt; 1K,2%自由12834K / 13040K,暂停24ms + 6ms,总计137ms 05-10 00:21:30.400:D / dalvikvm(769):GC_FOR_ALLOC释放<1K,2%释放12835K / 13040K,暂停39ms,总计39ms 05-10 00:21:30.459:I / dalvikvm-heap(769):将堆(frag case)增长到19.399MB,用于7077904字节分配 05-10 00:21:30.619:D / dalvikvm(769):GC_CONCURRENT释放0K,2%释放19747K / 19956K,暂停73ms + 19ms,总计160ms 05-10 00:21:30.869:D / dalvikvm(769):GC_FOR_ALLOC释放3072K,17%自由16677K / 19956K,暂停40ms,总计41ms 05-10 00:21:30.879:I / dalvikvm-heap(769):将堆(frag case)增长到19.402MB,用于3145744字节分配 05-10 00:21:31.041:D / dalvikvm(769):GC_CONCURRENT释放&lt; 1K,2%free 19749K / 19956K,暂停74ms + 19ms,总计164ms 05-10 00:21:31.449:D / dalvikvm(769):GC_FOR_ALLOC释放<1K,2%释放19749K / 19956K,暂停39ms,总计39ms 05-10 00:21:31.519:I / dalvikvm-heap(769):将堆(frag case)增长到26.152MB,用于7077904字节分配 05-10 00:21:31.699:D / dalvikvm(769):GC_CONCURRENT释放0K,1%释放26661K / 26872K,暂停73ms + 20ms,总计178ms 05-10 00:22:17.261:D / dalvikvm(769):GC_FOR_ALLOC释放3075K,13%释放23610K / 26848K,暂停49ms,总计56ms 05-10 00:22:17.269:I / dalvikvm-heap(769):将堆(frag case)增长到26.171MB,用于3145744字节分配 05-10 00:22:17.449:D / dalvikvm(769):GC_CONCURRENT释放&lt; 1K,1%free 26681K / 26848K,暂停75ms + 19ms,总计183ms 05-10 00:22:17.881:D / dalvikvm(769):GC_FOR_ALLOC释放&lt; 1K,1%free 26681K / 26848K,暂停47ms,总计47ms 05-10 00:22:17.881:I / dalvikvm-heap(769):强制收集707904字节分配的SoftReferences 05-10 00:22:17.949:D / dalvikvm(769):GC_BEFORE_OOM释放9K,1%免费26671K / 26848K,暂停70ms,总计71ms 05-10 00:22:17.949:E / dalvikvm-heap(769):7077904字节分配的内存不足。 05-10 00:22:17.959:I / dalvikvm(769):&#34; main&#34; prio = 5 tid = 1 RUNNABLE 05-10 00:22:17.959:I / dalvikvm(769):|基团=&#34;主&#34; sCount = 0 dsCount = 0 obj = 0x40a729a0 self = 0x2a00bba8 05-10 00:22:17.959:I / dalvikvm(769):| sysTid = 769 nice = 0 sched = 0/0 cgrp = apps handle = 1073849308 05-10 00:22:17.959:I / dalvikvm(769):| state = R schedstat =(6087547791 3674255993 433)utm = 429 stm = 179 core = 0 05-10 00:22:17.959:I / dalvikvm(769):在android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 05-10 00:22:17.959:I / dalvikvm(769):在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502) 05-10 00:22:17.959:I / dalvikvm(769):在android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355) 05-10 00:22:17.959:I / dalvikvm(769):在android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785) 05-10 00:22:17.959:I / dalvikvm(769):在android.content.res.Resources.loadDrawable(Resources.java:1965) 05-10 00:22:17.959:I / dalvikvm(769):在android.content.res.Resources.getDrawable(Resources.java:660) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.ImageView.resolveUri(ImageView.java:616) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.ImageView.setImageResource(ImageView.java:349) 05-10 00:22:17.971:I / dalvikvm(769):at net.learn2develop.Gallery.GalleryActivity $ ImageAdapter.getView(GalleryActivity.java:93) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.Gallery.makeAndAddView(Gallery.java:865) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:819) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.Gallery.fillToGalleryRight(Gallery.java:763) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.Gallery.trackMotionScroll(Gallery.java:393) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.Gallery.onScroll(Gallery.java:1043) 05-10 00:22:17.971:I / dalvikvm(769):在android.view.GestureDetector.onTouchEvent(GestureDetector.java:572) 05-10 00:22:17.971:I / dalvikvm(769):在android.widget.Gallery.onTouchEvent(Gallery.java:958) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.View.dispatchTouchEvent(View.java:7246) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 05-10 00:22:17.979:I / dalvikvm(769):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 05-10 00:22:17.979:I / dalvikvm(769):at com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:1953) 05-10 00:22:17.989:I / dalvikvm(769):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405) 05-10 00:22:17.989:I / dalvikvm(769):在android.app.Activity.dispatchTouchEvent(Activity.java:2410) 05-10 00:22:17.989:I / dalvikvm(769):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1901) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.View.dispatchPointerEvent(View.java:7426) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl $ WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4342) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.ViewRootImpl $ ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4382) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:749) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.Choreographer.doCallbacks(Choreographer.java:562) 05-10 00:22:17.989:I / dalvikvm(769):在android.view.Choreographer.doFrame(Choreographer.java:530) 05-10 00:22:17.999:I / dalvikvm(769):在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:735) 05-10 00:22:17.999:I / dalvikvm(769):在android.os.Handler.handleCallback(Handler.java:725) 05-10 00:22:17.999:I / dalvikvm(769):在android.os.Handler.dispatchMessage(Handler.java:92) 05-10 00:22:17.999:I / dalvikvm(769):在android.os.Looper.loop(Looper.java:137) 05-10 00:22:17.999:I / dalvikvm(769):在android.app.ActivityThread.main(ActivityThread.java:5041) 05-10 00:22:17.999:I / dalvikvm(769):at java.lang.reflect.Method.invokeNative(Native Method) 05-10 00:22:17.999:I / dalvikvm(769):at java.lang.reflect.Method.invoke(Method.java:511) 05-10 00:22:17.999:I / dalvikvm(769):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793) 05-10 00:22:17.999:I / dalvikvm(769):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 05-10 00:22:17.999:I / dalvikvm(769):at dalvik.system.NativeStart.main(Native Method) 05-10 00:22:18:009:D / skia(769):---为缩放位图分配失败 05-10 00:22:19.089:E / InputEventReceiver(769):异常调度输入事件。
有人可以开导我吗?非常感谢任何帮助!