我正在创建一个待办事项列表,而当我运行我的应用程序时,它却无法运行,这会导致错误会话“ app”:安装失败。重新安装失败
“ cmd软件包install-create -r -t --full -S 2161096”返回错误“未知故障:cmd:找不到服务:软件包”
我已经尝试过将InstantRun转向。 我尝试在其他设备上使用Progam
我的应用程序从一个基本的登录页面开始,在该页面中,您使用密码登录,如果密码正确,则将您带到Pag2.java(下面列出的代码) 还有一个名为FileHelper.Java
的类我从YouTube教程中编写了此代码。(https://www.youtube.com/watch?v=YmRPIGFftp0)
通常我不寻求帮助,但我无法找到答案请帮助。
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.Toast;
import java.util.ArrayList;
public class Pag2 extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
private EditText itemET;
private Button btn;
private ListView itemsList;
private ArrayList<String> items;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pag2);
itemET = findViewById(R.id.item_edit_text);
btn = findViewById(R.id.add_btn);
itemsList = findViewById(R.id.items_list);
items = FileHelper.readData(this);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, items);
itemsList.setAdapter(adapter);
FileHelper.writeData(items, this);
btn.setOnClickListener(this);
itemsList.setOnItemClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.add_btn:
String itemEntered = itemET.getText().toString();
adapter.add(itemEntered);
itemET.setText("");
FileHelper.writeData(items, this);
Toast.makeText(this, "Item Added", Toast.LENGTH_SHORT).show();
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
items.remove(position);
adapter.notify();
Toast.makeText(this, "Delete", Toast.LENGTH_SHORT).show();
}
}
//This Is FileHelper.java
package com.example.wetext;
import android.content.Context;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class FileHelper {
public static final String FILENAME ="listinfo.dat";
public static void writeData(ArrayList<String> items, Context context){
try {
FileOutputStream fos = context.openFileOutput(FILENAME, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(items);
oos.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static ArrayList<String> readData(Context context){
ArrayList<String> itemList = null;
try {
FileInputStream fis = context.openFileInput(FILENAME);
ObjectInputStream ois = new ObjectInputStream(fis);
itemList = (ArrayList<String>) ois.readObject();
} catch (FileNotFoundException e) {
itemList = new ArrayList<>();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return itemList;
}
}