I'm developing an Android proyect and I get an "Unfortunately, Kana has stopped" error whenever I try to launch it. Kana is the name of my proyect. I'm newbie on Android Developing and I think the problem is that I instantiated an Object from a second java class on my MainActivity class and I guess that's not ok?
If that's the case, how can I use other Java classes apart from Activities (which need an XML file too)? I mean, my Java class isn't an Activity and I want it to run in background, just to use it's methods.
Can someone help me please? And excuse my poor english, if you need more info I'll try to explain it.
My activity:
package kana.menu;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
public class KanaActivity extends Activity {
/** Called when the activity is first created. */
private TextView tv1;
private EditText et1;
private Mensaje m1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv1=(TextView)findViewById(R.id.textView1);
et1=(EditText)findViewById(R.id.editText1);
}
public void mensaje(View view){
m1=new Mensaje("Hola");
tv1.setText(m1.getMensaje()+et1.getText().toString());
}
}
My java class I want to instantiate:
package kana.menu;
public class Mensaje {
private String msg="";
public Mensaje(String mensaje){
msg=mensaje;
}
public Mensaje(){}
public void setMensaje(String mensaje){
msg=mensaje;
}
public String getMensaje(){
return this.msg;
}
public void borrarMensaje(){
this.msg="";
}
}