我从AsyncTask中的数据库中获取数据,如果它为null,我想要Toast一个警告文本.我在AsyncTask中尝试但是我知道它不是在工作线程中调用的.这是我的doInBackground方法:
protected String doInBackground(Boolean... params) {
String result = null;
StringBuilder sb = new StringBuilder();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet( "http://191.162.2.235/getProducts.php?login=1&user_name="+UserName+"&user_pass="+Password);
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() != 200) {
Log.d("MyApp", "Server encountered an error");
}
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF8"));
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
if ( result …Run Code Online (Sandbox Code Playgroud) 我尝试在导航抽屉中创建一个ExpandableListView.我尝试了一个示例代码但是在编译之前我遇到了这个错误.
public class MainActivity extends Activity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.left_drawer);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
Run Code Online (Sandbox Code Playgroud)
错误在这一行:listAdapter = new ExpandableListAdapter(this,listDataHeader,listDataChild);
为什么它说无法实例化ExpandableListAdapter类型?
这个警告是什么意思?我开发了一个Android应用程序,我在logcat中看到了这个警告.此警告不会导致关闭应用程序.一切都没有任何问题或中断,但它可能导致我的应用程序中看不到的一些问题?
Continue logcat: at android.view.ViewRoot.<init>(ViewRoot.java:261)
atandroid.view.WindowManagerImpl.addView(WindowManagerImpl.java:170)....
Run Code Online (Sandbox Code Playgroud)