I am new at android. I followed tutorials from http://www.youtube.com/watch?v=1JyC_xv20yE
There is no error in program. But emulator gives “the application stopped unexpectedly”
log file as
04-11 19:50:14.295: D/AndroidRuntime(338): Shutting down VM
04-11 19:50:14.295: W/dalvikvm(338): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-11 19:50:14.315: E/AndroidRuntime(338): FATAL EXCEPTION: main
04-11 19:50:14.315: E/AndroidRuntime(338): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sql/com.sql.SQLiteExample}: java.lang.ClassCastException: com.sql.SQLiteExample
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.os.Looper.loop(Looper.java:123)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-11 19:50:14.315: E/AndroidRuntime(338): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 19:50:14.315: E/AndroidRuntime(338): at java.lang.reflect.Method.invoke(Method.java:507)
04-11 19:50:14.315: E/AndroidRuntime(338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-11 19:50:14.315: E/AndroidRuntime(338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-11 19:50:14.315: E/AndroidRuntime(338): at dalvik.system.NativeStart.main(Native Method)
04-11 19:50:14.315: E/AndroidRuntime(338): at com.sql.SQLiteExample.onCreate(SQLiteExample.java:28)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 19:50:14.315: E/AndroidRuntime(338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-11 19:50:14.315: E/AndroidRuntime(338): ... 11 more
04-11 19:55:14.435: I/Process(338): Sending signal. PID: 338 SIG: 9
04-11 20:02:38.005: W/dalvikvm(367): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-11 20:02:38.045: E/AndroidRuntime(367): FATAL EXCEPTION: main
04-11 20:02:38.045: E/AndroidRuntime(367): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sql/com.sql.SQLiteExample}: java.lang.ClassCastException: com.sql.SQLiteExample
04-11 20:02:38.045: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-11 20:02:38.045: E/AndroidRuntime(367): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-11 20:02:38.045: E/AndroidRuntime(367): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-11 20:02:38.045: E/AndroidRuntime(367): at android.os.Looper.loop(Looper.java:123)
04-11 20:02:38.045: E/AndroidRuntime(367): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-11 20:02:38.045: E/AndroidRuntime(367): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 20:02:38.045: E/AndroidRuntime(367): at java.lang.reflect.Method.invoke(Method.java:507)
04-11 20:02:38.045: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-11 20:02:38.045: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-11 20:02:38.045: E/AndroidRuntime(367): at dalvik.system.NativeStart.main(Native Method)
04-11 20:02:38.045: E/AndroidRuntime(367): Caused by: java.lang.ClassCastException: com.sql.SQLiteExample
04-11 20:02:38.045: E/AndroidRuntime(367): at com.sql.SQLiteExample.onCreate(SQLiteExample.java:28)
04-11 20:02:38.045: E/AndroidRuntime(367): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 20:02:38.045: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-11 20:02:38.045: E/AndroidRuntime(367): ... 11 more
04-11 20:07:38.165: I/Process(367): Sending signal. PID: 367 SIG: 9
SQLiteexample.java as
package com.sql;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class SQLiteExample extends Activity implements OnClickListener{
/** Called when the activity is first created. */
Button sqlUpdate,sqlView;
EditText sqllocation,sqllongi,sqllati;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sqliteexample);
sqlUpdate = (Button)findViewById(R.id.bsqlupdate);
sqlView = (Button)findViewById(R.id.bsqlopenview);
sqllongi = (EditText)findViewById(R.id.longi);
sqllati = (EditText)findViewById(R.id.lati);
sqllocation = (EditText)findViewById(R.id.location1);
sqlView.setOnClickListener((android.view.View.OnClickListener) this);
sqlUpdate.setOnClickListener((android.view.View.OnClickListener) this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId())
{
case R.id.bsqlupdate:
boolean wrk=true;
try{
String location = sqllocation.getText().toString();
String longi = sqllongi.getText().toString();
String lati = sqllongi.getText().toString();
Cornte entry = new Cornte(this);
entry.open();
entry.createEntry(location , longi, lati);
entry.close();
}catch (Exception e){
wrk= false;
String error=e.toString();
Dialog d=new Dialog(this);
d.setTitle("NO!!!");
TextView tv =new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}finally{
if(wrk)
{
Dialog d=new Dialog(this);
d.setTitle("YUP!!!");
TextView tv =new TextView(this);
tv.setText("SUCCESS");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.bsqlopenview:
Intent i =new Intent("com.sql.SQLVIEW");
startActivity(i);
break;
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}
The error is in:
You can see it in your logcat:
I’ll explain, first try learning to use the logcat, mostly you should just start at the bottom of the error and search for the lines with your namespace (in this case com.sql.SQLiteExample), now you can see what method made your app crash, in this example: ‘onCreate’ but most important is the file + line number where the error occured!
ClassCastException means that you want to put an Object into an Object it isn’t…
School example you got BaseObjects ‘Animal’ which has some ChildObjects ‘Dogg’ & ‘Cat’ but now you are trying to do the following:
Well that won’t work since that ‘apple’ has nothing to do with the Class ‘Animal’… I hope you understand…