- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
在尝试将我的 JSON
信息解析为 ListView
时,我不断收到以下错误。
09-10 19:31:02.560 11200-11200/com.example.aids.a09application E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aids.a09application, PID: 11200
android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.Resources.getText(Resources.java:1178)
at android.widget.TextView.setText(TextView.java:5157)
at com.example.aids.a09application.StandingsAdapter.getView(StandingsAdapter.java:65)
at android.widget.AbsListView.obtainView(AbsListView.java:3229)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1396)
at android.widget.ListView.onMeasure(ListView.java:1303)
at android.view.View.measure(View.java:21046)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:21046)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:21046)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:21046)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21046)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:21046)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6460)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:785)
at android.view.View.measure(View.java:21046)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2562)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1629)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1878)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
上面的 Logcat
声明错误是我的 StandingsAdapter
类的第 65 行,它在下面。第 66 行是 standingsHolder.txt_id.setText( standings.getTeam_id() );
public class StandingsAdapter extends ArrayAdapter {
List list = new ArrayList();
public StandingsAdapter(@NonNull Context context, @LayoutRes int resource) {
super( context, resource );
}
public void add(Standings object) {
super.add( object );
list.add( object );
}
@Override
public int getCount() {
return list.size();
}
@Nullable
@Override
public Object getItem(int position) {
return list.get( position );
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View row;
row = convertView;
StandingsHolder standingsHolder;
if(row ==null){
LayoutInflater layoutInflater= (LayoutInflater) this.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
row = layoutInflater.inflate(R.layout.row_layout, parent, false);
standingsHolder = new StandingsHolder();
standingsHolder.tx_id = (TextView) row.findViewById( R.id.sec_1 );
standingsHolder.txt_id = (TextView) row.findViewById( R.id.sec_2 );
standingsHolder.tx_fn = (TextView) row.findViewById( R.id.sec_3 );
standingsHolder.tx_ln = (TextView) row.findViewById( R.id.sec_4 );
standingsHolder.tx_pos = (TextView) row.findViewById( R.id.sec_5 );
standingsHolder.tx_po = (TextView) row.findViewById( R.id.sec_6 );
row.setTag( standingsHolder );
}
else
{
standingsHolder = (StandingsHolder) row.getTag();
}
Standings standings = (Standings)this.getItem( position );
standingsHolder.tx_id.setText( standings.getDriver_id() );
standingsHolder.txt_id.setText( standings.getTeam_id() );
standingsHolder.tx_fn.setText( standings.getFirstName() );
standingsHolder.tx_ln.setText( standings.getLastName() );
standingsHolder.tx_pos.setText( standings.getPosition() );
standingsHolder.tx_po.setText( standings.getPoints() );
return row;
}
static class StandingsHolder {
TextView tx_id, txt_id, tx_fn, tx_ln, tx_pos, tx_po;
}
}
我将发布我的 android 应用程序中涉及此错误的其他类。下面是我的 Standings 类
public class Standings {
private int driver_id;
private int team_id;
private String firstName;
private String lastName;
private int position;
private int points;
public Standings(int driver_id, int team_id, String firstName, String lastName, int position, int points) {
this.setDriver_id( driver_id );
this.setTeam_id( team_id );
this.setFirstName( firstName );
this.setLastName( lastName );
this.setPosition( position );
this.setPoints( points );
}
public int getDriver_id() {
return driver_id;
}
public void setDriver_id(int driver_id) {
this.driver_id = driver_id;
}
public int getTeam_id() {
return team_id;
}
public void setTeam_id(int team_id) {
this.team_id = team_id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
}
下面是我的 StandingList fragment
,它是 Main Fragment
,其中包含用于下载 JSON
和解析 JSON< 的按钮
找到了。
public class StandingsList extends Fragment implements View.OnClickListener {
//make member variable is Views
Button mButton;
Button mButton1;
TextView mResult;
String JSON_RESPONSE;
String json_string;
ProgressDialog mProgressDialog;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate( R.layout.fragment_standings, container, false );
//get reference of the views
mButton = (Button) view.findViewById( R.id.button );
mButton1 = (Button) view.findViewById( R.id.buttontwo );
mResult = (TextView) view.findViewById( R.id.result );
mButton1.setOnClickListener(this);
//when button is clicked
mButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
//call the getJsonResponse method and fetch the response from the server
new getJsonResponse().execute();
}
} );
return view;
}
public class getJsonResponse extends AsyncTask<Void, Void, String> {
String serverUrl;
public getJsonResponse() {
mProgressDialog = new ProgressDialog( getActivity() );
mProgressDialog.setMessage( "Please Wait" );
mProgressDialog.setTitle( "Processing" );
mProgressDialog.setCancelable( false );
}
@Override
protected void onPreExecute() {
//set the url from we have to fetch the json response
serverUrl = "http://163.172.142.145/get_info.php";
mProgressDialog.show();
}
@Override
protected String doInBackground(Void... params) {
try {
URL url = new URL( serverUrl );
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( inputStream ) );
StringBuilder stringBuilder = new StringBuilder();
while ((JSON_RESPONSE = bufferedReader.readLine()) != null) {
stringBuilder.append( JSON_RESPONSE + "\n" );
}
inputStream.close();
bufferedReader.close();
httpURLConnection.disconnect();
return stringBuilder.toString().trim();
} catch (MalformedURLException e) {
Log.e( TAG, "MalformedURLException: " + e ); //print exception message to log
} catch (IOException e) {
Log.e( TAG, "IOException: " + e ); //print exception message to log
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate( values );
}
@Override
protected void onPostExecute(String result) {
//set the result which is returned by doInBackground() method to result textView
mResult.setText( result );
mProgressDialog.dismiss();
json_string = result;
}
}
public void onClick(View view){
switch (view.getId()) {
case R.id.buttontwo:
Intent intent = new Intent(getActivity(), DisplayListView.class);
intent.putExtra( "json_data",json_string );
startActivity( intent );
break;
}
}
}
我拥有的最后一个 class
与 JSON
Parse 一起工作的是 Display in List View 类
,这意味着它的名字是什么。下面是:
public class DisplayListView extends AppCompatActivity {
String json_string;
JSONObject jsonObject;
JSONArray jsonArray;
StandingsAdapter standingsAdapter;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.display_list_view_layout );
listView= (ListView) findViewById( R.id.ListViewParse );
standingsAdapter = new StandingsAdapter(this,R.layout.row_layout);
listView.setAdapter( standingsAdapter );
json_string = getIntent().getExtras().getString( "json_data" );
try {
jsonArray = new JSONObject(json_string).getJSONArray("server_response");
int count = 0;
int driver_id, team_id, position, points;
String firstName, lastName;
while(count<jsonArray.length())
{
JSONObject JO = jsonArray.getJSONObject(count);
driver_id = JO.getInt( "Driver_id" );
team_id =JO.getInt( "Team_id" );
firstName = JO.getString( "First_name" );
lastName= JO.getString( "Last_name" );
position= JO.getInt( "Position" );
points = JO.getInt( "Points" );
Standings standings = new Standings(driver_id, team_id, firstName, lastName, position, points );
standingsAdapter.add( standings );
count++;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
最近开始学习MongoDB。今天老师教了我们 mongoexport 命令。在练习时,我遇到了一个典型的问题,包括教练在内的其他同学都没有遇到过。我在我的 Windows 10 机器上使用 Mongo
我是 JSON Schema 的新手,读过什么是 JSON Schema 等等。但我不知道如何将 JSON Schema 链接到 JSON 以针对该 JSON Schema 进行验证。谁能解释一下?
在 xml 中,我可以在另一个 xml 文件中包含一个文件并使用它。如果您的软件从 xml 获取配置文件但没有任何方法来分离配置,如 apache/ngnix(nginx.conf - site-av
我有一个 JSON 对象,其中包含一个本身是 JSON 对象的字符串。我如何反序列化它? 我希望能够做类似的事情: #[derive(Deserialize)] struct B { c: S
考虑以下 JSON { "a": "{\"b\": 12, \"c\": \"test\"}" } 我想定义一个泛型读取 Reads[Outer[T]]对于这种序列化的 Json import
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve
我的旧项目在 MySQL 中有 Standard JSON 格式的数据。 对于我在 JS (Node.js) 和 DynamoDB 中的全新项目,关于 Standard JSON格式: 是否建议将其转
JSON 值字符串、数字、true、false、null 是否是有效的 JSON? 即,是 true 一个有效的 JSON 文档?还是必须是数组/对象? 一些验证器接受这个(例如 http://jso
我有一个 JSON 字符串,其中一个字段是文本字段。这个文本字段可以包含用户在 UI 中输入的文本,如果他们输入的文本是 JSON 文本,也许是为了说明一些编码,我需要对他们的文本进行编码,以便它不会
我正在通过 IBM MQ 调用处理数据,当由 ColdFusion 10 (10,0,11,285437) 序列化时,0 将作为 +0.0 返回,它会导致无效的 JSON并且无法反序列化。 stPol
我正在从三个数组中生成一个散列,然后尝试构建一个 json。我通过 json object has array 成功了。 require 'json' A = [['A1', 'A2', 'A3'],
我从 API 接收 JSON,响应可以是 30 种类型之一。每种类型都有一组唯一的字段,但所有响应都有一个字段 type 说明它是哪种类型。 我的方法是使用serde .我为每种响应类型创建一个结构并
我正在下载一个 JSON 文件,我已将其检查为带有“https://jsonlint.com”的有效 JSON 到文档目录。然后我打开文件并再次检查,结果显示为无效的 JSON。这怎么可能????这是
我正在尝试根据从 API 接收到的数据动态创建一个 JSON 对象。 收到的示例数据:将数据解码到下面给出的 CiItems 结构中 { "class_name": "test", "
我想从字符串转换为对象。 来自 {"key1": "{\n \"key2\": \"value2\",\n \"key3\": {\n \"key4\": \"value4\"\n }\n
目前我正在使用以下代码将嵌套的 json 转换为扁平化的 json: import ( "fmt" "github.com/nytlabs/gojsonexplode" ) func
我有一个使用来自第三方 API 的数据的应用程序。我需要将 json 解码为一个结构,这需要该结构具有“传入”json 字段的 json 标签。传出的 json 字段具有不同的命名约定,因此我需要不同
我想使用 JSON 架构来验证某些值。我有两个对象,称它们为 trackedItems 和 trackedItemGroups。 trackedItemGroups 是组名称和 trackedItem
考虑以下案例类模式, case class Y (a: String, b: String) case class X (dummy: String, b: Y) 字段b是可选的,我的一些数据集没有字
我正在存储 cat ~/path/to/file/blah | 的输出jq tojson 在一个变量中,稍后在带有 JSON 内容的 curl POST 中使用。它运作良好,但它删除了所有换行符。我知
我是一名优秀的程序员,十分优秀!