I've run into sort of a strange problem.
I'm working on an application targetAPI = 11. I'm using theActionbar.TabListener to implement two tabs and everything works great. However I now created a new "values-de" folder for German strings to use for German devices. Now, when I set my device to German and want to launch the application, it immediately crashes having a nullpointer in:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Why does it only occur with the device set to German (I assume it has something to do with my values-de, I just copied the entire "values" folder, renaming the copy to "values-de")
And how can I fix this without huge design workarounds? It works perfectly for the English language but I'd like to add multi-language support.
Thanks.
EDIT 1 - Stacktrace: (sorry forgot)
03-18 01:56:02.575: E/AndroidRuntime(23037): FATAL EXCEPTION: main
03-18 01:56:02.575: E/AndroidRuntime(23037): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.motioncoding.mobilesms/com.motioncoding.mobilesms.core.LaunchActivity}: java.lang.NullPointerException
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.os.Looper.loop(Looper.java:137)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-18 01:56:02.575: E/AndroidRuntime(23037): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 01:56:02.575: E/AndroidRuntime(23037): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 01:56:02.575: E/AndroidRuntime(23037): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-18 01:56:02.575: E/AndroidRuntime(23037): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-18 01:56:02.575: E/AndroidRuntime(23037): at dalvik.system.NativeStart.main(Native Method)
03-18 01:56:02.575: E/AndroidRuntime(23037): Caused by: java.lang.NullPointerException
03-18 01:56:02.575: E/AndroidRuntime(23037): at com.motioncoding.mobilesms.core.LaunchActivity.onCreate(LaunchActivity.java:43)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.Activity.performCreate(Activity.java:5104)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-18 01:56:02.575: E/AndroidRuntime(23037): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-18 01:56:02.575: E/AndroidRuntime(23037): ... 11 more
Problem with copying over styles.xml from values to values-<lang> is that it is not allowed and confuses Android since it is a duplicate. However allowed resources in values-<lang> are strings.xml and arrays.xml as these resources are the only ones that are subject to become translated.
However it is possible to have styles.xml, dimens.xml and colors.xml in values-<lang> folders when they are targeted specific versions of the API. So they would have to be in i.e. values-de-v11.
Related
I'm trying to run a check as if (Environment.DIRECTORY_DOCUMENTS == null) however when I do get to this line, I get a null pointer exception. Now I know that there is no Documents Directory on the device I'm testing, so it should give me a null value and move into the block of code, but I want it to actually check it. I just gives an error.
My logcat shows:
03-18 11:11:24.667: E/AndroidRuntime(5183): FATAL EXCEPTION: main
03-18 11:11:24.667: E/AndroidRuntime(5183): java.lang.NoSuchFieldError: android.os.Environment.DIRECTORY_DOCUMENTS
03-18 11:11:24.667: E/AndroidRuntime(5183): at com.example.testapp.MainActivity$3.onClick(MainActivity.java:640)
03-18 11:11:24.667: E/AndroidRuntime(5183): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:168)
03-18 11:11:24.667: E/AndroidRuntime(5183): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 11:11:24.667: E/AndroidRuntime(5183): at android.os.Looper.loop(Looper.java:137)
03-18 11:11:24.667: E/AndroidRuntime(5183): at android.app.ActivityThread.main(ActivityThread.java:4514)
03-18 11:11:24.667: E/AndroidRuntime(5183): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 11:11:24.667: E/AndroidRuntime(5183): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 11:11:24.667: E/AndroidRuntime(5183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
03-18 11:11:24.667: E/AndroidRuntime(5183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
03-18 11:11:24.667: E/AndroidRuntime(5183): at dalvik.system.NativeStart.main(Native Method)
How do I check (programmatically) if there is a documents directory on my device?
Environment.DIRECTORY_DOCUMENTS field is added in API Level 19.
So you can change the code as below to support for different versions:
File currentDir = null;
if (Build.VERSION.SDK_INT >= 19) {
currentDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));
}else{
currentDir = new File(Environment.getExternalStorageDirectory() + "/Documents");
}
As see here Environment.DIRECTORY_DOCUMENTS field is added in API Level 19 (Android 4.4(KITKAT))
Make sure using API 19 for project and in AndroidManifest.xml
I'm developing an app with Google Maps API v2, I've tested it and it is pretty working on HTC Desire 500, Samsung Galaxy SIII mini and Mediacom Phonepad. But on Nexus 5 (with Android Kitkat 4.4.2) my app crashes when I click the button that opens the "ActivityMap".
I've also installed the API 19 of Android. Anyone can help me? Every kind of help will be greatly appreciated. If you need my code, just ask me.
03-18 11:21:37.240: E/AndroidRuntime(18406): FATAL EXCEPTION: main
03-18 11:21:37.240: E/AndroidRuntime(18406): Process: com.example.myapplication, PID: 18406
03-18 11:21:37.240: E/AndroidRuntime(18406): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MapActivity}: java.lang.NullPointerException
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.os.Handler.dispatchMessage(Handler.java:102)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.os.Looper.loop(Looper.java:136)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-18 11:21:37.240: E/AndroidRuntime(18406): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 11:21:37.240: E/AndroidRuntime(18406): at java.lang.reflect.Method.invoke(Method.java:515)
03-18 11:21:37.240: E/AndroidRuntime(18406): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-18 11:21:37.240: E/AndroidRuntime(18406): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-18 11:21:37.240: E/AndroidRuntime(18406): at dalvik.system.NativeStart.main(Native Method)
03-18 11:21:37.240: E/AndroidRuntime(18406): Caused by: java.lang.NullPointerException
03-18 11:21:37.240: E/AndroidRuntime(18406): at com.example.myapplication.MapActivity.onCreate(MapActivity.java:53)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.Activity.performCreate(Activity.java:5231)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-18 11:21:37.240: E/AndroidRuntime(18406): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-18 11:21:37.240: E/AndroidRuntime(18406): ... 11 more
Here i am trying to consume one web service.And i am trying to show json data from that web service into listview in android? But i am getting errors on my logcat like below
Logcat
03-18 18:11:51.830: I/System.out(296): Transparent 17170445
03-18 18:11:51.990: W/System.err(296): java.net.SocketException: Permission denied
03-18 18:11:52.000: W/System.err(296): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
03-18 18:11:52.000: W/System.err(296): at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
03-18 18:11:52.000: W/System.err(296): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
03-18 18:11:52.000: W/System.err(296): at java.net.Socket.checkClosedAndCreate(Socket.java:873)
03-18 18:11:52.010: W/System.err(296): at java.net.Socket.connect(Socket.java:1020)
03-18 18:11:52.010: W/System.err(296): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
03-18 18:11:52.010: W/System.err(296): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
03-18 18:11:52.010: W/System.err(296): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
03-18 18:11:52.010: W/System.err(296): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
03-18 18:11:52.010: W/System.err(296): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
03-18 18:11:52.010: W/System.err(296): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
03-18 18:11:52.010: W/System.err(296): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
03-18 18:11:52.010: W/System.err(296): at com.example.png.StationsListActivity.callService(StationsListActivity.java:97)
03-18 18:11:52.010: W/System.err(296): at com.example.png.StationsListActivity$3.run(StationsListActivity.java:78)
03-18 18:11:52.429: D/AndroidRuntime(296): Shutting down VM
03-18 18:11:52.429: W/dalvikvm(296): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-18 18:11:52.449: E/AndroidRuntime(296): FATAL EXCEPTION: main
03-18 18:11:52.449: E/AndroidRuntime(296): java.lang.NullPointerException
03-18 18:11:52.449: E/AndroidRuntime(296): at com.example.png.StationsListActivity$1.handleMessage(StationsListActivity.java:43)
03-18 18:11:52.449: E/AndroidRuntime(296): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 18:11:52.449: E/AndroidRuntime(296): at android.os.Looper.loop(Looper.java:123)
03-18 18:11:52.449: E/AndroidRuntime(296): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-18 18:11:52.449: E/AndroidRuntime(296): at java.lang.reflect.Method.invokeNative(Native Method)
3-18 18:11:52.449: E/AndroidRuntime(296): at java.lang.reflect.Method.invoke(Method.java:521)
03-18 18:11:52.449: E/AndroidRuntime(296): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-18 18:11:52.449: E/AndroidRuntime(296): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-18 18:11:52.449: E/AndroidRuntime(296): at dalvik.system.NativeStart.main(Native Method)
Thanks for you precious time!..
Have you added below permission in your manifest.xml?
<uses-permission android:name="android.permission.INTERNET" />
Add Internet permission to your manifest:
<uses-permission android:name="android.permission.INTERNET"/>
Please add internet permission to your manifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
I sent a server request and shown user a progress dialog with following properties
waitDialog = new ProgressDialog(this);
waitDialog.setMessage(getText(R.string.msg_plz_wait));
waitDialog.setIndeterminate(true);
waitDialog.show();
Step1: Sent server request
Step2: Shown User a Dialog
Step3: User presses home button while dialog was visible and showing
Step4: data came from server passed to list adapter but could not found resource and throws Resource not found exception that is handled and then ProgressDialog throws following exception.
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): FATAL EXCEPTION: main
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): java.lang.NullPointerException
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.AbsListView.obtainView(AbsListView.java:1432)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.ListView.makeAndAddView(ListView.java:1745)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.ListView.fillDown(ListView.java:670)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.ListView.fillFromTop(ListView.java:727)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.ListView.layoutChildren(ListView.java:1598)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.View.layout(View.java:7175)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.View.layout(View.java:7175)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.View.layout(View.java:7175)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.View.layout(View.java:7175)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.View.layout(View.java:7175)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.os.Looper.loop(Looper.java:123)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at java.lang.reflect.Method.invoke(Method.java:507)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-18 12:18:11.050: ERROR/AndroidRuntime(15113): at dalvik.system.NativeStart.main(Native Method)
IMHO, It has nothing to do with the ProgressDialog, But caused by the listview, this is all I could tell based on your question.
It's not you progress dialog.
It's something you are doing, after your server request is ready.
What does happen, if user doesn't press the home button? Does issue still occur?
Have you tried doing waitDialog.setCancelable(false)? Does that make a difference?
I am trying to clear a webview from the view in my application.
I clear this by using: MyWebView.loadUrl("about:blank");
This works sometimes, but other times when I load the emulator this gives a force close error:
03-18 14:58:29.560: ERROR/AndroidRuntime(380): FATAL EXCEPTION: main
03-18 14:58:29.560: ERROR/AndroidRuntime(380): java.lang.NullPointerException
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at com.edu.WordJumbleMain$5.onClick(WordJumbleMain.java:168)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at android.view.View.performClick(View.java:2408)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at android.view.View$PerformClick.run(View.java:8816)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at android.os.Handler.handleCallback(Handler.java:587)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at android.os.Handler.dispatchMessage(Handler.java:92)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at android.os.Looper.loop(Looper.java:123)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at java.lang.reflect.Method.invoke(Method.java:521)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-18 14:58:29.560: ERROR/AndroidRuntime(380): at dalvik.system.NativeStart.main(Native Method)
Is there any other way to clear the webview from the view.
Thanks
Raj,
Perhaps you simply want to use the clearView() method?
how to hide the "Web Page not available" text when web View fails to load the page. MyWebView.clearView() is not working.