- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从 mysql 数据库中获取 2 列,所以我将它们传递到 HashMap 中,然后在警报对话框的 ListView 中显示它们,但我遇到了无法解决的错误
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
int sucess;
try {
List<NameValuePair> Ext = new ArrayList<NameValuePair>();
Ext.add(new BasicNameValuePair("NotificationID", NotificationID));
json3 = jsonParser2.makeHttpRequest(Get_Ext,"POST", Ext);
//json3 = jsonParser2.getJSONFromUrl(Get_Ext);
//getExt = json3.getString("FieldTitle");
//getExtVal=json3.getString("FieldValue");
Rec2 = new JSONArray(getExt);
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < Rec2.length(); i++){
JSONObject c = Rec2.getJSONObject(i);
map = new HashMap<String, String>();
map.put("FieldTitle", c.getString("FieldTitle"));
map.put("FieldValue", c.getString("FieldValue"));
MyArrList.add(map);
}
} catch (Exception e) {
// TODO: handle exception
}
return null ;
}
这里是我的onpostexecute:
@Override
protected void onPostExecute(String st){
Toast.makeText(getApplicationContext(), "done" , Toast.LENGTH_LONG).show();
SimpleAdapter ExtAdpt = new SimpleAdapter(getApplicationContext(), MyArrList, R.layout.extended_message, new String[]{"FieldTitle","FieldValue"}, new int[]{R.id.ExtTitle, R.id.ExtMessage});
AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(Notifications.this);
LayoutInflater inflat = getLayoutInflater();
View turnview = (View) inflat.inflate(R.layout.extended_list, null);
alertDialogBuilder2.setView(turnview);
alertDialogBuilder2.setTitle("Call for Action ...");
Extlist = (ListView) turnview.findViewById(R.id.extendedlst);
Extlist.setAdapter(ExtAdpt);
alertDialogBuilder2.create();
alertDialogBuilder2.show();
我已经在浏览器上测试了我的 php 文件,它运行良好
我的日志
03-10 18:35:23.048: W/dalvikvm(1720): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-10 18:35:23.088: E/AndroidRuntime(1720): FATAL EXCEPTION: main
03-10 18:35:23.088: E/AndroidRuntime(1720): java.lang.NullPointerException
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.widget.SimpleAdapter.getCount(SimpleAdapter.java:93)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.widget.ListView.setAdapter(ListView.java:462)
03-10 18:35:23.088: E/AndroidRuntime(1720): at com.example.notifier.Notifications$GetExtended.onPostExecute(Notifications.java:492)
03-10 18:35:23.088: E/AndroidRuntime(1720): at com.example.notifier.Notifications$GetExtended.onPostExecute(Notifications.java:1)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.os.Handler.dispatchMessage(Handler.java:99)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.os.Looper.loop(Looper.java:137)
03-10 18:35:23.088: E/AndroidRuntime(1720): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-10 18:35:23.088: E/AndroidRuntime(1720): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 18:35:23.088: E/AndroidRuntime(1720): at java.lang.reflect.Method.invoke(Method.java:511)
03-10 18:35:23.088: E/AndroidRuntime(1720): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-10 18:35:23.088: E/AndroidRuntime(1720): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-10 18:35:23.088: E/AndroidRuntime(1720): at dalvik.system.NativeStart.main(Native Method)
请帮帮我:'(
完整代码:
package com.example.notifier;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.zip.Inflater;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.google.android.gms.drive.metadata.internal.ParentDriveIdSet;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class Notifications extends Activity {
Spinner tiFi , ty ;
ProgressDialog progs;
Button sh ;
SqlCommands sql;
String[] Fields , name , name2, name3;
SimpleCursorAdapter Adpt ;
ListView NotiLst , Extlist;
ImageView Hip, Ntype , arr ;
String getGrp_url = "http:///db_get_grp.php";
String Get_Ext = "http:///get_Extended.php";
String result , fld, bdy ,NotificationID , getExt , getExtVal;
JSONParser jsonParser = new JSONParser();
JSONParser jsonParser2 = new JSONParser();
JSONObject json = null ;
JSONObject json3 = null ;
private static final String TAG_SUCCESS = "success";
private static final String TAG_Rec = "Grp_Name";
private static final String TAG_RESULTS="result";
ArrayList<HashMap<String, String>> MyArrList;
JSONArray Rec = null;
JSONArray Rec2 = null;
JSONArray Rec3 = null;
final List<String> list1 = new ArrayList<String>();
final List<String> list2 = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
tiFi = (Spinner) findViewById(R.id.timFilt);
ty = (Spinner) findViewById(R.id.typFilt);
NotiLst = (ListView) findViewById(R.id.msgListView);
Hip =(ImageView) findViewById(R.id.hi);
Ntype =(ImageView) findViewById(R.id.Prio);
sh =(Button) findViewById(R.id.dbadd);
Extlist = (ListView) findViewById(R.id.extendedlst);
new GetGroup().execute();
sh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/* sql = new SqlCommands(getApplicationContext());
Boolean x = sql.AddEntry(2,"aaaa","fggdfg",2,3,3,"2016-03-07");
if (x==true){
Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(), "not done", Toast.LENGTH_LONG).show();
}
CusListView();*/
Toast.makeText(getApplicationContext(), NotificationID , Toast.LENGTH_LONG).show();
}
});
/* tiFi.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
switch (arg2) {
case 0:
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
*/
/*
arr.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor c = sql.GetData();
}
});
*/
NotiLst.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// TODO Auto-generated method stub
sql = new SqlCommands(getApplicationContext());
Cursor cr = (Cursor) NotiLst.getItemAtPosition(position);
//Cursor cr = sql.gettype((int) id);
if (cr.moveToFirst())
{
fld = cr.getString(cr.getColumnIndex("Types"));}
switch (fld) {
case "1":
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Notifications.this);
alertDialogBuilder.setTitle("Message");
if (cr.moveToFirst())
{
bdy = cr.getString(cr.getColumnIndex("Body"));}
alertDialogBuilder.setMessage(bdy);
alertDialogBuilder.create();
alertDialogBuilder.show();
break;
case "2":
if (cr.moveToFirst())
{
NotificationID = cr.getString(cr.getColumnIndex("NotificationID"));
}
new GetExtended().execute();
break;
}
}});
String[] items = new String[]{"Ever", "Today", "Yseterday", "Last Week" , "Last Month" };
ArrayAdapter<String> timAdpt = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items);
tiFi.setAdapter(timAdpt);
tiFi.setOnItemSelectedListener(new OnItemSelectedListener() {
@SuppressLint("NewApi")
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
// TODO Auto-generated method stub
sql = new SqlCommands(getApplicationContext());
String[] mFields = new String[]{SqlCommands.Subject, SqlCommands.Body, SqlCommands.DateTime};
int [] tview = new int []{R.id.sbj,R.id.bdy,R.id.DT};
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
switch (position) {
case 1:
cal.add(Calendar.DATE, 0);
String d = dateFormat.format(cal.getTime());
Cursor c = sql.getDate(d) ;
SimpleCursorAdapter Dadpt = new SimpleCursorAdapter(getApplicationContext(),R.layout.items, c , mFields, tview ,0 );
Dadpt.notifyDataSetChanged();
NotiLst.setAdapter(Dadpt);
break;
case 2:
cal.add(Calendar.DATE, -1);
String d1 = dateFormat.format(cal.getTime());
Cursor c1 = sql.getDate(d1) ;
SimpleCursorAdapter Dadpt1 = new SimpleCursorAdapter(getApplicationContext(),R.layout.items, c1 , mFields, tview ,0 );
Dadpt1.notifyDataSetChanged();
NotiLst.setAdapter(Dadpt1);
break;
case 3:
cal.add(Calendar.DATE, 0);
String d2 = dateFormat.format(cal.getTime());
Cursor c2 = sql.getDateweek(d2) ;
SimpleCursorAdapter Dadpt2 = new SimpleCursorAdapter(getApplicationContext(),R.layout.items, c2 , mFields, tview ,0 );
Dadpt2.notifyDataSetChanged();
NotiLst.setAdapter(Dadpt2);
break;
case 4:
cal.add(Calendar.DATE, -30);
String d3 = dateFormat.format(cal.getTime());
Cursor c3 = sql.getDate(d3) ;
SimpleCursorAdapter Dadpt3 = new SimpleCursorAdapter(getApplicationContext(),R.layout.items, c3 , mFields, tview ,0 );
Dadpt3.notifyDataSetChanged();
NotiLst.setAdapter(Dadpt3);
break;
default:
CusListView();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
public void spin(){
ArrayAdapter<String> grpAdpt = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, name);
ty.setAdapter(grpAdpt);
ty.setOnItemSelectedListener(new OnItemSelectedListener() {
@SuppressLint("NewApi")
@Override
public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {
// TODO Auto-generated method stub
//Toast.makeText(parent.getContext(), "The planet is " +parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
switch (position) {
case 0:
CusListView();
break;
default:
sql = new SqlCommands(getApplicationContext());
Fields = new String[]{SqlCommands.Subject, SqlCommands.Body, SqlCommands.DateTime};
int [] Dview = new int []{R.id.sbj,R.id.bdy,R.id.DT};
//int P = (int)parent.getItemAtPosition(position);
Cursor c = sql.getSpecificData(position) ;
SimpleCursorAdapter Adpt2 = new SimpleCursorAdapter(getApplicationContext(),R.layout.items, c , Fields, Dview ,0 );
Adpt2.notifyDataSetChanged();
NotiLst.setAdapter(Adpt2);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}}); }
@SuppressLint("NewApi")
private void CusListView(){
sql = new SqlCommands(getApplicationContext());
Fields = new String[]{SqlCommands.Subject, SqlCommands.Body, SqlCommands.DateTime};
int [] Dview = new int []{R.id.sbj,R.id.bdy,R.id.DT};
Cursor c = sql.GetData();
Adpt = new SimpleCursorAdapter(getApplicationContext(),R.layout.items, c , Fields, Dview ,0 );
NotiLst.setAdapter(Adpt);
}
private void IsHigh(){
sql = new SqlCommands(getApplicationContext());
Cursor c = sql.GetData();
if (c.moveToFirst())
{
do {
int IShig = c.getColumnIndex("Priopity");
if(IShig!=1){
Hip.setVisibility(View.INVISIBLE);
}
else {
Hip.setVisibility(View.VISIBLE);
}
} while (c.moveToNext());
}
sql.close();
}
public void showSpinner(){
try {
JSONObject json;
Rec = new JSONArray(result);
name = new String[Rec.length()];
for(int i=0;i<Rec.length();i++){
json = Rec.getJSONObject(i);
name[i] = json.getString("Grp_Name");
}
for (int i=0; i<name.length; i++){
list1.add(name[i]);
}
spin();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
class GetGroup extends AsyncTask<String, String, String >{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try{
json = jsonParser.getJSONFromUrl(getGrp_url);
Log.d("Login attempt", json.toString());
result = json.getString("Grp_Name");
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
return result;
}
@Override
protected void onPostExecute(String result){
showSpinner();
}
}
class GetExtended extends AsyncTask<String, String, String>{
@SuppressLint("NewApi")
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
int sucess;
try {
List<NameValuePair> Ext = new ArrayList<NameValuePair>();
Ext.add(new BasicNameValuePair("NotificationID", NotificationID));
json3 = jsonParser2.makeHttpRequest(Get_Ext,"POST", Ext);
//json3 = jsonParser2.getJSONFromUrl(Get_Ext);
//getExt = json3.getString("FieldTitle");
//getExtVal=json3.getString("FieldValue");
Rec2 = new JSONArray();
MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < Rec2.length(); i++){
JSONObject c = Rec2.getJSONObject(i);
map = new HashMap<String, String>();
map.put("FieldTitle", c.getString("FieldTitle"));
map.put("FieldValue", c.getString("FieldValue"));
MyArrList.add(map);
}
} catch (Exception e) {
// TODO: handle exception
}
return null ;
}
@Override
protected void onPostExecute(String st){
Toast.makeText(getApplicationContext(), "done" , Toast.LENGTH_LONG).show();
SimpleAdapter ExtAdpt = new SimpleAdapter(getApplicationContext(), MyArrList, R.layout.extended_message, new String[]{"FieldTitle","FieldValue"}, new int[]{R.id.ExtTitle, R.id.ExtMessage});
AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(Notifications.this);
LayoutInflater inflat = getLayoutInflater();
View turnview = (View) inflat.inflate(R.layout.extended_list, null);
alertDialogBuilder2.setView(turnview);
alertDialogBuilder2.setTitle("Call for Action ...");
Extlist = (ListView) turnview.findViewById(R.id.extendedlst);
Extlist.setAdapter(ExtAdpt);
alertDialogBuilder2.create();
alertDialogBuilder2.show();
}
}
}
最佳答案
MyArrList 似乎是 doInBackground 方法的本地对象,您也没有从 doInBackground 方法返回。或者您正试图在 onPostExecute 中访问该对象,该对象为 null 或不退出。
关于java - android 将 json 传递给 HashMap 到 alertdialog 中显示的 llistview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35924694/
Github:https://github.com/jjvang/PassIntentDemo 我一直在关注有关按 Intent 传递对象的教程:https://www.javacodegeeks.c
我有一个 View ,其中包含自动生成的 text 类型的 input 框。当我单击“通过电子邮件发送结果”按钮时,代码会将您带到 CalculatedResults Controller 中的 Em
我有一个基本的docker镜像,我将以此为基础构建自己的镜像。我没有基础镜像的Dockerfile。 基本上,基本镜像使用两个--env arg,一个接受其许可证,一个选择在容器中激活哪个框架。我可以
假设我想计算 2^n 的总和,n 范围从 0 到 100。我可以编写以下内容: seq { 0 .. 100 } |> Seq.sumBy ((**) 2I) 但是,这与 (*) 或其他运算符/函数不
我有这个网址: http://www.example.com/get_url.php?ID=100&Link=http://www.test.com/page.php?l=1&m=7 当我打印 $_G
我想将 window.URL.createObjectURL(file) 创建的地址传递给 dancer.js 但我得到 GET blob:http%3A//localhost/b847c5cd-aa
我想知道如何将 typedef 传递给函数。例如: typedef int box[3][3]; box empty, *board[3][3]; 我如何将 board 传递给函数?我
我正在将一些代码从我的 Controller 移动到核心数据应用程序中的模型。 我编写了一个方法,该方法为我定期发出的特定获取请求返回 NSManagedObjectID。 + (NSManagedO
为什么我不能将类型化数组传递到采用 any[] 的函数/构造函数中? typedArray = new MyType[ ... ]; items = new ko.observableArray(ty
我是一名新的 Web 开发人员,正在学习 html5 和 javascript。 我有一个带有“选项卡”的网页,可以使网页的某些部分消失并重新出现。 链接如下: HOME 和 JavaScript 函
我试图将对函数的引用作为参数传递 很难解释 我会写一些伪代码示例 (calling function) function(hello()); function(pass) { if this =
我在尝试调用我正在创建的 C# 项目中的函数时遇到以下错误: System.Runtime.InteropServices.COMException: Operation is not allowed
使用 ksh。尝试重用当前脚本而不修改它,基本上可以归结为如下内容: `expr 5 $1 $2` 如何将乘法命令 (*) 作为参数 $1 传递? 我首先尝试使用“*”,甚至是\*,但没有用。我尝试
我一直在研究“Play for Java”这本书,这本书非常棒。我对 Java 还是很陌生,但我一直在关注这些示例,我有点卡在第 3 章上了。可以在此处找到代码:Play for Java on Gi
我知道 Javascript 中的对象是通过引用复制/传递的。但是函数呢? 当我跳到一些令人困惑的地方时,我正在尝试这段代码。这是代码片段: x = function() { console.log(
我希望能够像这样传递参数: fn(a>=b) or fn(a!=b) 我在 DjangoORM 和 SQLAlchemy 中看到了这种行为,但我不知道如何实现它。 最佳答案 ORM 使用 specia
在我的 Angular 项目中,我最近将 rxjs 升级到版本 6。现在,来自 npm 的模块(在 node_modules 文件夹内)由于一些破坏性更改而失败(旧的进口不再有效)。我为我的代码调整了
这个问题在这里已经有了答案: The issue of * in Command line argument (6 个答案) 关闭 3 年前。 我正在编写一个关于反向波兰表示法的 C 程序,它通过命
$(document).ready(function() { function GetDeals() { alert($(this).attr("id")); } $('.filter
下面是一个例子: 复制代码 代码如下: use strict; #这里是两个数组 my @i =('1','2','3'); my @j =('a','b','c'); &n
我是一名优秀的程序员,十分优秀!