gpt4 book ai didi

android - Android-无法解释的崩溃

转载 作者:行者123 更新时间:2023-12-03 17:37:01 25 4
gpt4 key购买 nike

我正在尝试使用以下代码在图像 View 中显示位图图像:

ImageView imageView = (ImageView) findViewById(R.id.item_picture);
byte[] decodedString = Base64.decode(temp, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);

但是,它总是在最后一行崩溃,我不知道为什么。

继承人的日志:
09-08 09:29:01.626: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:01.636: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:01.636: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:01.636: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:01.636: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:01.636: E/SoundPool(275): error loading /system/media/audio/ui/KeypressStandard.ogg
09-08 09:29:01.636: E/SoundPool(275): error loading /system/media/audio/ui/KeypressSpacebar.ogg
09-08 09:29:01.646: E/SoundPool(275): error loading /system/media/audio/ui/KeypressDelete.ogg
09-08 09:29:01.646: E/SoundPool(275): error loading /system/media/audio/ui/KeypressReturn.ogg
09-08 09:29:03.549: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:03.556: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:03.556: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:03.556: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:03.556: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:03.556: E/SoundPool(275): error loading /system/media/audio/ui/KeypressStandard.ogg
09-08 09:29:03.556: E/SoundPool(275): error loading /system/media/audio/ui/KeypressSpacebar.ogg
09-08 09:29:03.566: E/SoundPool(275): error loading /system/media/audio/ui/KeypressDelete.ogg
09-08 09:29:03.566: E/SoundPool(275): error loading /system/media/audio/ui/KeypressReturn.ogg
09-08 09:29:08.727: E/AndroidRuntime(7288): FATAL EXCEPTION: main
09-08 09:29:08.727: E/AndroidRuntime(7288): java.lang.NullPointerException
09-08 09:29:08.727: E/AndroidRuntime(7288): at com.myCompany.myApp.SearchActivity$MyListAdapter.getView(SearchActivity.java:139)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.AbsListView.obtainView(AbsListView.java:2177)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.ListView.measureHeightOfChildren(ListView.java:1247)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.ListView.onMeasure(ListView.java:1159)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.View.measure(View.java:15848)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:698)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:494)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.View.measure(View.java:15848)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.View.measure(View.java:15848)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.View.measure(View.java:15848)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-08 09:29:08.727: E/AndroidRuntime(7288): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.View.measure(View.java:15848)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.os.Handler.handleCallback(Handler.java:730)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.os.Handler.dispatchMessage(Handler.java:92)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.os.Looper.loop(Looper.java:137)
09-08 09:29:08.727: E/AndroidRuntime(7288): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-08 09:29:08.727: E/AndroidRuntime(7288): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 09:29:08.727: E/AndroidRuntime(7288): at java.lang.reflect.Method.invoke(Method.java:525)
09-08 09:29:08.727: E/AndroidRuntime(7288): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-08 09:29:08.727: E/AndroidRuntime(7288): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-08 09:29:08.727: E/AndroidRuntime(7288): at dalvik.system.NativeStart.main(Native Method)
09-08 09:29:11.216: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:11.226: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:11.226: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:11.226: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:11.236: E/SoundPool(275): error loading /system/media/audio/ui/Effect_Tick.ogg
09-08 09:29:11.236: E/SoundPool(275): error loading /system/media/audio/ui/KeypressStandard.ogg
09-08 09:29:11.236: E/SoundPool(275): error loading /system/media/audio/ui/KeypressSpacebar.ogg
09-08 09:29:11.236: E/SoundPool(275): error loading /system/media/audio/ui/KeypressDelete.ogg
09-08 09:29:11.246: E/SoundPool(275): error loading /system/media/audio/ui/KeypressReturn.ogg

这里的getView代码:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//make sure we have a view to work with (may have been given null)
View itemView = convertView;

if(itemView == null)
{
itemView = getLayoutInflater().inflate(R.layout.list_item, parent, false);
}

//Find the user to work with
Users currentUser = myUsers.get(position);

//Fill the view
TextView text;
text = (TextView) itemView.findViewById(R.id.item_name);
text.setText(currentUser.getName());

text = (TextView) itemView.findViewById(R.id.item_location);
text.setText(currentUser.getLocation());

String temp = currentUser.getPicture();

if(!temp.equals("noPicture"))
{
ImageView imageView = (ImageView) findViewById(R.id.item_picture);
byte[] decodedString = Base64.decode(temp, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);
}

return itemView;
}

谁能看到它崩溃的原因?

最佳答案

更换:

ImageView imageView = (ImageView) findViewById(R.id.item_picture);

与:
ImageView imageView = (ImageView) itemView.findViewById(R.id.item_picture);

您应该在 View中搜索 itemView,因为此 View在主布局中不存在,因此仅在 ListView项中可见,因此 findViewById将返回 null

关于android - Android-无法解释的崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18684259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com