- 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();
}
}
}
我有一个静态类。 static class AppDirectory { public static string PACSTEMP = Path.Combine(Path.GetTempPa
我已经设置了一个启用了推送通知的 iOS 应用。 我可以将消息推送到应用程序,例如角标(Badge)计数工作并相应更新。 但我从未在锁屏或其他地方看到标准的推送通知弹出窗口,但手机会振动,因此消息会通
我们有一个带有 Web 应用程序和一堆 Windows 服务的系统,它们在做一些后台工作。 每当我们需要对系统进行更实质性的更改时,我们最终不得不发出 IIS 重置,然后手动重新启动所有相关的 Win
我有以下几行 John SMith: A Pedro Smith: B Jonathan B: A John B: B Luis Diaz: A Scarlet Diaz: B 我需要获得所有获得
我正在编写一个 Java 客户端(在 weblogic 10.3 上)来调用一个安全的网络服务。我已获得安装在 cacerts、DemoIdentity.jks 和 DemoTrust,jks 中的客
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎偏离主题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或 include a mini
我正在尝试调用void方法addToList,该方法将通过用户传递给它的两个字符串除外。我检查了dataSource类,以确保它确实接受了那些作为参数。问题是我在该方法调用上始终收到标识符>预期错误,
我的任务:使用scanner方法从一行数据中提取字符串、 float 和整数。 数据格式为: Random String, 240.5 51603 Another String, 41.6 59087
这个问题已经有答案了: What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? (25 个回答)
首先我实例化一个游戏状态 class GameState extends state{ ArrayList levels; int currentLevelID; public GameState()
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我有一个实现为单例的 Controller 对象,它有一个可以随时驱逐对象的缓存。当一个对象即将被删除时,我想通知任何使用此 Controller 的类,以便它们能够做出适当的响应。我对这种行为的第一
因此,我尝试跨集群发送消息,该消息将包含一个 User 对象,该对象是一个可序列化类。 当我发送 String 或 int 时,它工作正常,消息发送没有问题,并且集群上的所有 channel 都收到它
我试图创建的程序是一个基本游戏,用户输入网格大小,选择 block 接收增加分数的奖品、从分数中夺走分数的强盗或结束游戏的炸弹。我收到堆栈流错误,但我不明白为什么? 抱歉,代码量很大,我只是无法找到问
使用此代码我会得到什么ConcurrentModificationException?我有一个同步(监听器)锁。 private void notifyListeners(MediumRenditio
我想在捕获 DeadlineExceededError 后正确退出。我还剩下多少钱来清理? 例如, try: do_some_work() except DeadlineExceededError
我有 2 个 Intranet 站点: http://intranetv1/ http://intranetv2/ v1基于.NET 1.1,v2基于.NET 3.5 在 v1 上,我创建了一个网页,
我有一个在 Linux 3.12 上运行的 C 程序。该程序产生几个子进程。其中一个进程会生成一个线程,该线程运行一段时间然后终止。当该子进程运行时,它会执行 epoll_wait()。 epoll_
我能够将 APNS 集成到我的应用程序中。现在我想在用户点击它或用户在使用应用程序时收到通知时处理通知。我使用下面的代码在收到通知时显示警报对话框: func application(applicat
当我试图在浏览器上运行这段代码时,出现了以下错误。"错误响应错误代码:501消息:不支持的方法(“POST”)。错误码解释:501-服务器不支持该操作。" 浏览器控制台出现以下错误: "1.加载资源失
我是一名优秀的程序员,十分优秀!