In order to get my feet wet with Android development, I thought I'd hire a guy to lay the foundation of a simple app for me, then I would try and take it from there. So far it's worked really well. I've been able to learn quite a bit.
One of the issues I am having though is that I keep getting crash reports about an bug that is causing the app to crash, but the app works perfectly for me on my Nexus S! I am used to iOS development where everything is uniform...
A number of reports are coming in with the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.elan.readerJapanese/com.elan.readerJapanese.Language}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.elan.readerJapanese.Language.onCreate(Language.java:91)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
... 11 more'
Which is pretty hard for me to understand. I understand that there is a null pointer exception being thrown in my language class's onCreate method, but I can't get it to reproduce! So I have no idea what may be going on. Here is the code for my onCreate method. `public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.title_list_menu);
me=this;
Bundle extras = getIntent().getExtras();
DatabaseHelper myDatabaseAdapter;
myDatabaseAdapter = DatabaseHelper.getInstance(me);
if(extras !=null)
{
if(!myDatabaseAdapter.databaseReady()){
try{
myDatabaseAdapter.copyDatabase2();
DatabaseHelper_Spa myDatabaseAdapter_spa = DatabaseHelper_Spa.getInstance(me);
myDatabaseAdapter_spa.copyDatabaseSpanish2();
}catch(Exception e){
e.printStackTrace();
}
myDatabaseAdapter.databaseReady();
}
}else{
//myDatabaseAdapter.close();
if(!myDatabaseAdapter.databaseReady()){
try{
myDatabaseAdapter.copyDatabase2();
DatabaseHelper_Spa myDatabaseAdapter_spa = DatabaseHelper_Spa.getInstance(me);
myDatabaseAdapter_spa.copyDatabaseSpanish2();
}catch(Exception e){
e.printStackTrace();
}
myDatabaseAdapter.databaseReady();
}
else if(myDatabaseAdapter.getSaveVerse()[0]!=null||!myDatabaseAdapter.getSaveVerse()[0].equals("")){
String data[]=myDatabaseAdapter.getSaveVerse();
Intent intent=new Intent(Language.this, Verse.class);
intent.putExtra("language",data[0]);
intent.putExtra("volume_id",data[1]);
intent.putExtra("chapter",data[2]);
intent.putExtra("book",data[3]);
intent.putExtra("book_id",data[4]);
intent.putExtra("multiple_languages",false);
startActivity(intent);
}
}
// listImage=new Bitmap[]{BitmapFactory.decodeResource(getResources(), R.drawable.sharing),BitmapFactory.decodeResource(getResources(), R.drawable.contact_us),BitmapFactory.decodeResource(getResources(), R.drawable.about)};
m_orders = new ArrayList<SettingsObject>();
this.m_adapter = new AboutAdapter(this, R.layout.language_row, m_orders);
setListAdapter(this.m_adapter);
viewOr开发者_如何学JAVAders = new Runnable(){
@Override
public void run() {
getOrders();
}
};
Thread thread = new Thread(null, viewOrders, "MagentoBackground");
thread.start();
}`
It would be great if someone could tell me if they see something out of line in the above code, or if not,m what I can do to try and debug this error. Like I said, I am having trouble with it because the error won't reproduce on my device, so it's hard to see what people are getting.
Thanks!
If you look at the stack trace you see that the exception occured at line 91 in Language.java.
You can tell this from the last part of the exception output:
Caused by: java.lang.NullPointerException at com.elan.readerJapanese.Language.onCreate(Language.java:91) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751) ... 11 more'
Without knowing the line I would guess it has something to do with the database stuff.
Could the method getSaveVerse
ever return null?
I'm guessing your line number have changed since that stack trace because if line 91 is the one that you say the only that could cause that stack trace is if myDatabaseAdapter
is null but that would make the line before (else if(myDatabaseAdapter.getSaveVerse()[0]!=null||!myDatabaseAdapter.getSaveVerse()[0].equals("")){
) to crash.
I don't see how it's possible for that stack trace to occur unless you have some other object modifying myDatabaseAdapter
That said make sure that your DatabaseHelper
doesn't modify your Activity
精彩评论