我知道我在这里写错了一些东西,我试图从JSON动态显示多行项目但是得到以下异常,
01-22 11:18:27.814: E/AndroidRuntime(438): FATAL EXCEPTION: main
01-22 11:18:27.814: E/AndroidRuntime(438): java.lang.NullPointerException
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.item.MultiLineItem.createView(MultiLineItem.java:44)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.view.ViewFactory.getView(ViewFactory.java:122)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.view.DocumentList.createView(DocumentList.java:52)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.view.ViewFactory.getContainer(ViewFactory.java:85)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.controller.Controller.createDocument(Controller.java:415)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.model.SublistChooser.checkNextListTemplate(SublistChooser.java:99)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.model.SublistChooser.checkNextListTemplate(SublistChooser.java:96)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.model.SublistChooser.start(SublistChooser.java:50)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.controller.Controller.startDocument(Controller.java:387)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.controller.Controller.startDocument(Controller.java:379)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.action.ActionExecutor.executeTaskAction(ActionExecutor.java:445)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.action.ActionExecutor.onAction(ActionExecutor.java:288)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.action.Action.execute(Action.java:133)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.nokia.view.PopupList$1.onClick(PopupList.java:72)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:920)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.widget.AdapterView.performItemClick(AdapterView.java:282)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.widget.AbsListView.performItemClick(AbsListView.java:1037)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2449)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.widget.AbsListView$1.run(AbsListView.java:3073)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.os.Handler.handleCallback(Handler.java:587)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.os.Looper.loop(Looper.java:132)
01-22 11:18:27.814: E/AndroidRuntime(438): at android.app.ActivityThread.main(ActivityThread.java:4123)
01-22 11:18:27.814: E/AndroidRuntime(438): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 11:18:27.814: E/AndroidRuntime(438): at java.lang.reflect.Method.invoke(Method.java:491)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-22 11:18:27.814: E/AndroidRuntime(438): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-22 11:18:27.814: E/AndroidRuntime(438): at dalvik.system.NativeStart.main(Native Method)
01-22 11:18:27.973: D/dalvikvm(438): GC_CONCURRENT freed 223K, 5% free 9758K/10247K, paused 9ms+27ms
01-22 11:18:34.123: I/Process(438): Sending signal. PID: 438 SIG: 9
这是我得到的代码NullPointerException
,我不知道如何将视图设置为List。 View
正在返回Null
但正常TextFields
的工作文件。请发布一些有用的代码。
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONObject;
import android.view.View;
import android.widget.ListView;
import com.nokia.view.BaseScreen;
import com.nokia.view.BaseView;
public class MultiLineItem extends Item implements BaseView{
private HashMap items;
private ArrayList list;
public MultiLineItem(BaseScreen pview){
super(pview);
list= new ArrayList();
items = new HashMap();
}
@Override
public int getItemID() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getValue() {
// TODO Auto-generated method stub
return null;
}
@Override
public View getItem() {
// TODO Auto-generated method stub
return view;
}
public void createView(JSONObject definition) {
String header=definition.optString("header");
items.put("header", header);
String text = definition.optString("text");
items.put("text", text);
list.add(items);
//((ListView)view).addFocusables(list, LIST);
}
public ArrayList getList(){
return list;
}
答案 0 :(得分:0)
Android
中有一个Widget,你必须使用ListView
。在ListView
设置Adapter
,在适配器中,您必须发送从Json
获得的所有数据。这是执行Android ListView Tutorial的示例。本教程将为您提供有关如何在Application中使用ListView的建议。