I have three class in my app.
First extends Activity
public class TestProjActivity extends Activity {
/** Called when the activity is first created. */
String my ="";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new Runnable() {
public void run() {
Translation th = new Translation(this);
my = th.doSomeJob();
}
}).start();
Log.d("ONCREATE", my);
}
}
Second is DBHelper
public class DBHelper {
private final Context myContext;
public DBHelper(Context context) {
this.myContext = context;
}
}
and third one extends DBhelper
public class Translation extends DBHelper {
public Translation(Runnable runnable) {
super((Context) runnable);
}
public String doSomeJob(){
return "Yes I DID!";
}
}
future I will change this classes to do real job but now,
when I run this I get this error:
- 05-11 13:15:53.003: E/AndroidRuntime(512): Uncaught handler: thread Thread-8 exiting due to uncaught exception
- 05-11 13:15:53.028: E/AndroidRuntime(512): java.lang.ClassCastException: iKA.PROJ.TestProjActivity$1
- 05-11 13:15:53.028: E/AndroidRuntime(512): at another.pack.Translation.(Translation.java:10)
- 05-11 13:15:53.028: E/AndroidRuntime(512): at iKA.PROJ.TestProjActivity$1.run(TestProjActivity.java:20)
- 05-11 13:15:53.028: E/AndroidRuntime(512): at java.lang.Thread.run(Thread.java:1096)
- 05-11 13:15:53.053: I/dalvikvm(512): threadid=7: reacting to signal 3
- 05-11 13:15:53.053: E/dalvikvm(512): Unable to open stack trace file ‘/data/anr/traces.txt’: Permission denied
- 05-11 13:20:53.135: I/Process(512): Sending signal. PID: 512 SIG: 9
What do I wrong ?
You’re trying to cast your
Runnableinto aContext. This is not possibleI think that you want to do is
and