I try to get the database path in the constructor of database helper class like this:
public DB_Nabege_helper(Context context) {
super(context, DBname, null, 1);
Nabege_context = context;
DBpath=Nabege_context.getDatabasePath(DBname).getPath();
}
When run app : crashed app
10-15 16:41:37.164: E/AndroidRuntime(1420): FATAL EXCEPTION: main
10-15 16:41:37.164: E/AndroidRuntime(1420): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.nabproduct.nabege/com.nabproduct.nabege.Collection_List_Activity}: java.lang.NullPointerException
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.os.Looper.loop(Looper.java:137)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-15 16:41:37.164: E/AndroidRuntime(1420): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 16:41:37.164: E/AndroidRuntime(1420): at java.lang.reflect.Method.invoke(Method.java:511)
10-15 16:41:37.164: E/AndroidRuntime(1420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-15 16:41:37.164: E/AndroidRuntime(1420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-15 16:41:37.164: E/AndroidRuntime(1420): at dalvik.system.NativeStart.main(Native Method)
10-15 16:41:37.164: E/AndroidRuntime(1420): Caused by: java.lang.NullPointerException
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.content.ContextWrapper.getDatabasePath(ContextWrapper.java:231)
10-15 16:41:37.164: E/AndroidRuntime(1420): at com.nabproduct.nabege.DB_Nabege_helper.<init>(DB_Nabege_helper.java:44)
10-15 16:41:37.164: E/AndroidRuntime(1420): at com.nabproduct.nabege.Collection_List_Activity.<init>(Collection_List_Activity.java:165)
10-15 16:41:37.164: E/AndroidRuntime(1420): at java.lang.Class.newInstanceImpl(Native Method)
10-15 16:41:37.164: E/AndroidRuntime(1420): at java.lang.Class.newInstance(Class.java:1319)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
10-15 16:41:37.164: E/AndroidRuntime(1420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
I add more code as an answer.
I see from the stacktrace that you create DB helper in the activity constructor or field initializer possibly. In both cases activity isn't initialized yet (moreover you don't need to override activity constructor in the most cases). Move DB helper assignment inside the activity onCreate() method.
Related
I try to change the package name.First, I rename package that is src folder, then select rename package name in android tools menu.Now when run the app: crashed the app.
Logcat errors :
10-15 15:35:19.747: E/AndroidRuntime(1272): FATAL EXCEPTION: main
10-15 15:35:19.747: E/AndroidRuntime(1272): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nabproduct.nabege/com.nabproduct.nabege.Collection_List_Activity}: java.lang.NullPointerException
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.os.Looper.loop(Looper.java:137)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-15 15:35:19.747: E/AndroidRuntime(1272): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 15:35:19.747: E/AndroidRuntime(1272): at java.lang.reflect.Method.invoke(Method.java:511)
10-15 15:35:19.747: E/AndroidRuntime(1272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-15 15:35:19.747: E/AndroidRuntime(1272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-15 15:35:19.747: E/AndroidRuntime(1272): at dalvik.system.NativeStart.main(Native Method)
10-15 15:35:19.747: E/AndroidRuntime(1272): Caused by: java.lang.NullPointerException
10-15 15:35:19.747: E/AndroidRuntime(1272): at com.nabproduct.nabege.DB_Nabege_helper.count_collection(DB_Nabege_helper.java:156)
10-15 15:35:19.747: E/AndroidRuntime(1272): at com.nabproduct.nabege.Collection_List_Activity.fill_listView(Collection_List_Activity.java:361)
10-15 15:35:19.747: E/AndroidRuntime(1272): at com.nabproduct.nabege.Collection_List_Activity.onCreate(Collection_List_Activity.java:199)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.Activity.performCreate(Activity.java:5008)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-15 15:35:19.747: E/AndroidRuntime(1272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
there is a lot of thing you should change. have you changed the application ID in the gradle file??? it doesn't change automatically. have you updated the android manifest file?
try considering there...
I set the database path with a string like this: "/data/data/com.example. nabege/databases/". I changed it and solved the problem.Thank you for answering
My App crash rarely
i want to get off this bug for ever.
this is the log that users Report
i tried so long on this but nothing helps
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.Master_}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.access$600(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xxx.xxx.HomeFragment.onActivityCreated(HomeFragment.java:140)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:566)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
at android.app.Activity.performStart(Activity.java:5018)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
... 11 more
I have a very basic activity with an ImageView of android:id="#+id/imageViewTest"
and then in the OnCreate method calling:
ImageView imageView = (ImageView)findViewById(R.id.imageViewTest);
// Set the background color to white
imageView.setBackgroundColor(Color.WHITE);
this gives error:
10-15 16:36:27.552 29097-29097/org.explore.self.beginner D/dalvikvm﹕ Late-enabling CheckJNI
10-15 16:36:28.017 29097-29097/org.explore.self.beginner D/AndroidRuntime﹕ Shutting down VM
10-15 16:36:28.017 29097-29097/org.explore.self.beginner W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d9b2a0)
10-15 16:36:28.042 29097-29097/org.explore.self.beginner E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.explore.self.beginner/org.selfexplore.android.view.activity.TestActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.selfexplore.android.view.activity.TestActivity.onCreate(TestActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
10-15 16:36:28.062 29097-29097/org.explore.self.beginner I/Process﹕ Sending signal. PID: 29097 SIG: 9
But when I do a
ImageView imageView = new ImageView(this);
it works fine, Why?
PS: I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing
Your layout you've set with setContentView() doesn't have a view with id imageViewTest and findViewById() returns null, or you haven't called setContentView() at all.
I have changed the theme for some activities, but when I want to run the AVD go to Force Stop.
This is my activity manifest:
<activity
android:name="com.example.gpsportalsms.LoginActivity"
android:theme="#android:style/Theme.Translucent."
android:label="#string/title_activity_login" >
<intent-filter>
and this is my xml activity:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.gpsportalsms.LoginActivity"
android:background="#drawable/background3"
tools:ignore="MergeRootFrame" >
</FrameLayout>
I add the LogCat in below:
06-29 16:10:24.015: W/dalvikvm(1420): threadid=1: thread exiting with uncaught exception (group=0xa4ceeb20)
06-29 16:10:24.015: E/AndroidRuntime(1420): FATAL EXCEPTION: main
06-29 16:10:24.015: E/AndroidRuntime(1420): Process: com.example.gpsportalsms, PID: 1420
06-29 16:10:24.015: E/AndroidRuntime(1420): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gpsportalsms/com.example.gpsportalsms.NotifySMSReceived}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.os.Handler.dispatchMessage(Handler.java:102)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.os.Looper.loop(Looper.java:136)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-29 16:10:24.015: E/AndroidRuntime(1420): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 16:10:24.015: E/AndroidRuntime(1420): at java.lang.reflect.Method.invoke(Method.java:515)
06-29 16:10:24.015: E/AndroidRuntime(1420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-29 16:10:24.015: E/AndroidRuntime(1420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-29 16:10:24.015: E/AndroidRuntime(1420): at dalvik.system.NativeStart.main(Native Method)
06-29 16:10:24.015: E/AndroidRuntime(1420): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
06-29 16:10:24.015: E/AndroidRuntime(1420): at com.example.gpsportalsms.NotifySMSReceived.onCreate(NotifySMSReceived.java:20)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.Activity.performCreate(Activity.java:5231)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-29 16:10:24.015: E/AndroidRuntime(1420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-29 16:10:24.015: E/AndroidRuntime(1420): ... 11 more
What is wrong?
Remove the "." in Theme.Translucent.
Use this
<activity
android:name="com.example.gpsportalsms.LoginActivity"
android:theme="#android:style/Theme.Translucent"
android:label="#string/title_activity_login" >
A quick search lands me into this SO question : How to make an Android Translucent theme a little darker?
The mentioned question however isn't much related to yours, but provides some reference. Haven't tried though.
As it says the code must be like
<activity
android:name="com.example.gpsportalsms.LoginActivity"
android:theme="#android:style/Theme.Translucent"
android:label="#string/title_activity_login" >
Notice the '.' shouldn't be there.
I get this error when running my code, and I don't receive anything back from json
10-15 00:29:22.396: WARN/System.err(562): java.lang.IllegalArgumentException: Illegal character in query at index 68: http://www.hotels-in-london-hotels.com/mytrolly/service.php?request={"mode":"category"}
10-15 00:29:22.425: WARN/System.err(562): at java.net.URI.create(URI.java:970)
10-15 00:29:22.425: WARN/System.err(562): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
10-15 00:29:22.436: WARN/System.err(562): at com.sampleapp.MainActivity$iTab.readTwitterFeed(MainActivity.java:128)
10-15 00:29:22.436: WARN/System.err(562): at com.sampleapp.MainActivity$iTab.<init>(MainActivity.java:65)
10-15 00:29:22.436: WARN/System.err(562): at java.lang.reflect.Constructor.constructNative(Native Method)
10-15 00:29:22.446: WARN/System.err(562): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
10-15 00:29:22.446: WARN/System.err(562): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
10-15 00:29:22.456: WARN/System.err(562): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
10-15 00:29:22.456: WARN/System.err(562): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
10-15 00:29:22.466: WARN/System.err(562): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
10-15 00:29:22.466: WARN/System.err(562): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-15 00:29:22.466: WARN/System.err(562): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-15 00:29:22.476: WARN/System.err(562): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
10-15 00:29:22.476: WARN/System.err(562): at android.app.Activity.setContentView(Activity.java:1647)
10-15 00:29:22.476: WARN/System.err(562): at com.sampleapp.MainActivity.onCreate(MainActivity.java:362)
10-15 00:29:22.486: WARN/System.err(562): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-15 00:29:22.486: WARN/System.err(562): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-15 00:29:22.486: WARN/System.err(562): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-15 00:29:22.496: WARN/System.err(562): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-15 00:29:22.496: WARN/System.err(562): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-15 00:29:22.496: WARN/System.err(562): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 00:29:22.506: WARN/System.err(562): at android.os.Looper.loop(Looper.java:123)
10-15 00:29:22.506: WARN/System.err(562): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-15 00:29:22.506: WARN/System.err(562): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 00:29:22.506: WARN/System.err(562): at java.lang.reflect.Method.invoke(Method.java:521)
10-15 00:29:22.506: WARN/System.err(562): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-15 00:29:22.506: WARN/System.err(562): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-15 00:29:22.506: WARN/System.err(562): at dalvik.system.NativeStart.main(Native Method)
Basically I'm trying to use json, and the problem I'm having is with this line
HttpGet httpGet = new HttpGet(
"http://www.hotels-in-london-hotels.com/mytrolly/service.php?request={\"mode\":\"category\"}");
I've encoded the string, and I still get the exception
try {
url = "http://www.hotels-in-london-hotels.com/mytrolly/service.php?request={\"mode\":\"category\"}";
String encodedurl = URLEncoder.encode(url,"UTF-8");
Log.d("TEST", encodedurl);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Any solutions?
You probably need to URL encode your parameter string. Try using URLEncoder
Character 68 is =, by the way.
Also, is there a problem beyond this warning (like you don't get desired result)? Note - it's not an error but warning.
The problem is the curly braces. I'd expect URLEncoder to take care of it, but you can also just manually replace them. '{' should be %7B and '}' should be "%7D".
This may helps you
String link="http://example.php?string1="+URLEncoder.encode(string1)+"&string2="+URLEncoder
.encode(string2)+"&string3="+URLEncoder.encode(string3)+"&string4="+URLEncoder.encode(string4)+"";