我已经基于一个函数创建了一个图像上传asynctask.上传后,我在onPostExecute上收到此错误.我在Runnable上读了一些Stackoverflow的答案,但我不断反复地得到错误,尽管实现了不同的解决方案.
我的代码:
class uploadFile extends AsyncTask<String, String, String> {
private ProgressDialog pDialog;
/**
* --------------------------------------------------------------------
* --------------------------------- Before starting background thread
* Show Progress Dialog
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Uploading file");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* --------------------------------------------------------------------
* --------------------------------- getting all recent articles and
* showing them in listview
*/
@Override
protected String doInBackground(String... args) {
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
String existingFileName = Environment.getExternalStorageDirectory() …Run Code Online (Sandbox Code Playgroud) 我在Stackoverflow上看了很多问题并尝试了很多解决方法,但它仍然没有用.
我想要实现的目标:

但我实现了这个目标:

这是我目前的xml代码:
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ic_action_search" />
Run Code Online (Sandbox Code Playgroud) 我已经阅读了Stackoverflow上的许多问题和答案,其中许多只是强调.cancel()了特殊的唯一ID.但是,现在无论我尝试多少次,我都无法取消它.
我唯一的身份证
final static int RQS_1 = 1337;
我的setAlarm函数.pickTime是当前的Activity,timesUp是另一个Service在时间到了时显示toast的类.
Intent intent = new Intent(pickTime.this, timesUp.class);
PendingIntent timesUpIntent = PendingIntent.getService(pickTime.this, RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
timesUpIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), timesUpIntent);
Run Code Online (Sandbox Code Playgroud)
我的cancelAlarm功能
Intent intent = new Intent(this, pickTime.class);
PendingIntent timesUpIntent = PendingIntent.getBroadcast(this, RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
if (timesUpIntent != null) {
alarmManager.cancel(timesUpIntent);
timesUpIntent.cancel();
Toast.makeText(getApplicationContext(), "Alarm is cancelled",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to stop timer",
Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
我的时间服务 …
我在 Hackerrank 上尝试了一个问题,我需要在其中创建一个数组数组(基本上是二维数组)。
我的首选衬垫是const counter = new Array(4).fill([])
但是,我意识到它会创建一个 2D 数组,但将任何函数应用于该数组都会使其应用于所有元素。
let count = new Array(4).fill([])
count[0].push("Test")
console.log(JSON.stringify(count))Run Code Online (Sandbox Code Playgroud)
结果将是所有子数组在其中具有相同的“测试”值。
最终的解决方案是:
let count = Array.from(Array(4), () => new Array());
count[0].push("Test")
console.log(JSON.stringify(count))Run Code Online (Sandbox Code Playgroud)
我可以问为什么它没有按预期工作吗?
我一直在阅读关于Stckoverflow的许多问题和答案.但还是找不到我实际使用的时间adapter.notifyDataSetChanged.
以前,在将所有项目添加到ArrayList之后,我做到了
adapter = new ListViewAdapter(MainActivity.this, menuItems);
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
它在我的手机上没有崩溃,模拟器和只有少数人发生了这次崩溃.
然后,我做到了.
adapter = new ListViewAdapter(MainActivity.this, menuItems);
adapter.notifyDataSetChanged();
lv.setAdapter(adapter);
与上述结果相同.
但我讨厌崩溃.我讨厌下载我的应用程序的人有FC.然后我尝试了这个,知道可能适配器必须刷新,然后我可以设置一个新的.
adapter.notifyDataSetChanged();
adapter = new ListViewAdapter(MainActivity.this, menuItems);
lv.setAdapter(adapter);
结果是在向下滚动几页[永不停止的列表视图]之后,它在我的手机上崩溃了.
也许是我不懂的.但是我们什么时候才开始使用adapter.notifyDataSetChanged?
如果它有帮助,这是我的完整代码.
`
private class firstLoad extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
setSupportProgressBarIndeterminateVisibility(true);
if (lv.getVisibility() == View.VISIBLE) {
lv.setVisibility(View.GONE);
}
}
protected Void doInBackground(Void... unused) {
try {
xml = parser.getXmlFromUrl(getURLFromXML + "main.php");
doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName(Consts.KEY_ITEM);
for (int i = …Run Code Online (Sandbox Code Playgroud) 假设我有一个字符串列表
const arr = ["a", "b", "c"];
Run Code Online (Sandbox Code Playgroud)
我究竟如何将其转换为对象,以使这些值成为任何对象的键?
const obj = {
a: "can be anything",
b: 2,
c: 0
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用
type TupleToObject<T extends readonly string[]> = {
[P in T[number]]: any;
};
Run Code Online (Sandbox Code Playgroud)
但它似乎不是强类型的。