当我在我的应用程序中按下按钮时,我不知道如何在.csv文件中编写参数或行。 我在我的代码中有这个,但我不确定是否需要创建另一个类或在onCreate方法中执行它。当我按下按钮时,应用停止,我不知道出了什么问题。
EditText newParam;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_parametros);
Button btnAgrParam = (Button) findViewById(R.id.btn_AgrParam);
btnAgrParam.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
newParam = (EditText)findViewById(R.id.label_NewParam);
try{
String csv ="C:\\Users\\Rubén\\Desktop\\Universidad\\TFG\\Plantilla.csv";
CSVWriter writer;
writer = new CSVWriter(new FileWriter(csv));
String parametro = newParam.getText().toString();
String datos = parametro;
writer.writeNext(datos);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
这是堆栈跟踪。
11-02 18:57:30.517:E / AndroidRuntime(9861):FATAL EXCEPTION:main 11-02 18:57:30.517:E / AndroidRuntime(9861):java.lang.NoClassDefFoundError:au.com.bytecode .opencsv.CSVWriter 11-02 18:57:30.517:E / AndroidRuntime(9861):at com.example.tfg.MenuParametros $ 2.onClick(MenuParametros.java:64)11-02 18:57:30.517:E / AndroidRuntime (9861):在android.view.View.performClick(View.java:2485)11-02 18:57:30.517:E / AndroidRuntime(9861):在android.view.View $ PerformClick.run(View.java: 9080)11-02 18:57:30.517:E / AndroidRuntime(9861):在android.os.Handler.handleCallback(Handler.java:587)11-02 18:57:30.517:E / AndroidRuntime(9861):at android.os.Handler.dispatchMessage(Handler.java:92)11-02 18:57:30.517:E / AndroidRuntime(9861):at android.os.Looper.loop(Looper.java:123)11-02 18: 57:30.517:E / AndroidRuntime(9861):在android.app.ActivityThread.main(ActivityThread.java:3683)11-02 18:57:30.517:E / AndroidRuntime(9861):at java.lang.reflect.Method .invokeNative(Native Method)11-02 18:57:30.517:E / Andro idRuntime(9861):at java.lang.reflect.Method.invoke(Method.java:507)11-02 18:57:30.517:E / AndroidRuntime(9861):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller .run(ZygoteInit.java:839)11-02 18:57:30.517:E / AndroidRuntime(9861):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)11-02 18:57 :30.517:E / AndroidRuntime(9861):at dalvik.system.NativeStart.main(Native Method)