NullPointerExceptionとは何か知っていますよね?しかし、このコード行で考えられる間違いは何ですか:
mealImage.setParseFile(campaign.getImage());
私にNullPointerException
?
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.parse.ParseImageView.setParseFile(com.parse.ParseFile)' on a null object reference
at com.alibdeir.signupactivity.mainAdapter.getItemView(mainAdapter.java:41)
at com.alibdeir.signupactivity.mainAdapter.getItemView(mainAdapter.java:19)
at com.parse.ParseQueryAdapter.getView(ParseQueryAdapter.java:606)
at android.widget.AbsListView.obtainView(AbsListView.java:2823)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1290)
at android.widget.ListView.onMeasure(ListView.java:1202)
at android.view.View.measure(View.java:18580)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464)
at android.view.View.measure(View.java:18580)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464)
at android.view.View.measure(View.java:18580)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:18580)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18580)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:18580)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18580)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2897)
at android.view.View.measure(View.java:18580)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2248)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1306)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1548)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
行 41: は、私が提供したコードの最初の行です。19 行目は次のとおりです。
public class mainAdapter extends ParseQueryAdapter<Campaign> {
では、何がヌルになるのでしょうか? 私の ParseImageView は正しい、正しいクラスと列名です。画像を取得するにはどうすればよいですか: Campaign.class:
@ParseClassName("Campaign")
public class Campaign extends ParseObject {
public Campaign() {
// default Constructor
}
public String getTitle() {
return getString("Title");
}
public String getDescription(){
return getString("Description");
}
public ParseUser getAuthor() {
return getParseUser("Owner");
}
public ParseFile getImage(){
return getParseFile("Picture");
}
}
さらに情報が必要ですか?
注:-1
私に向かわないでくださいNullPointerException
。だから、気をつけて!
編集:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<com.parse.ParseImageView
android:id="@android:id/icon"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#000000"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textColor="#454343"
/>
</TableRow>
</TableLayout>
getItemView() :
@Override
public View getItemView(Campaign campaign, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.list_single,null);
}
super.getItemView(campaign, v, parent);
ParseImageView mealImage = (ParseImageView) v.findViewById(R.id.icon);
ParseFile photoFile = campaign.getImage();
if (photoFile != null) {
mealImage.setParseFile(campaign.getImage());
mealImage.loadInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
// nothing to do
}
});
}
TextView titleTextView = (TextView) v.findViewById(R.id.title);
titleTextView.setText(campaign.getTitle());
TextView descriptionTextView = (TextView) v
.findViewById(R.id.description);
descriptionTextView.setText(campaign.getDescription());
return v;
}
編集:これは重複ではありません。nullPointerException とは何かを知っています。しかし、何がnullなのかわかりません。私は使用してmParseQueryAdapter.setImageKey("Picture")
、それは働いた