如果我的应用程序没有在我的手机上崩溃,并且我无法看到发生了什么,我该如何修复这个导致我的应用程序在其他手机上崩溃的错误?
为了让我涉足 Android 开发,我想我应该雇一个人为我打下一个简单应用程序的基础,然后我会尝试从那里开始它。到目前为止,效果非常好。我已经学到了很多东西。
我遇到的问题之一是,我不断收到有关导致应用程序崩溃的错误的崩溃报告,但该应用程序在我的 Nexus S 上完美运行!我习惯了 iOS 开发,一切都是统一的......
许多报告都出现以下错误:
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'
这对我来说很难理解。我知道我的语言类的 onCreate 方法中抛出了空指针异常,但我无法重现它!所以我不知道会发生什么。这是我的 onCreate 方法的代码。 `public void onCreate(Bundle savingInstanceState) {
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);
viewOrders = new Runnable(){
@Override
public void run() {
getOrders();
}
};
Thread thread = new Thread(null, viewOrders, "MagentoBackground");
thread.start();
}`
如果有人能告诉我他们是否在上面的代码中看到了不合规矩的东西,或者如果没有,我可以做什么来尝试调试这个错误,那就太好了。就像我说的,我遇到了麻烦,因为错误不会在我的设备上重现,所以很难看到人们得到了什么。
谢谢!
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);
viewOrders = 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果查看堆栈跟踪,您会发现异常发生在 Language.java 中的第 91 行。
您可以从异常输出的最后部分看出这一点:
在不知道该行的情况下,我猜它与数据库内容有关。
getSaveVerse 方法会返回 null 吗?
我猜您的行号自该堆栈跟踪以来已发生变化,因为如果第 91 行是您所说的唯一可能导致堆栈跟踪的行,则如果
myDatabaseAdapter
为 null,但这会使之前的行(else if(myDatabaseAdapter.getSaveVerse()[0]!=null||!myDatabaseAdapter.getSaveVerse()[0].equals("")){
) 崩溃。我不明白该堆栈跟踪是如何发生的,除非您有其他对象修改
myDatabaseAdapter
这就是说,请确保您的
DatabaseHelper
不会修改您的 ActivityIf 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:
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