Getting java.lang.NullPointerException In Android webView - android

I am working on an application in which i scan a QR code and using that I am opening the pdf related to it.
THIS IS MY CODE
if(uri.contains("abc"))
{
WebView webview= new WebView(getApplicationContext());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + uri);
but my application is crashing and i am getting java.lang.NullPointerException.
Please Help me. every help will be appreciated.
HERE IS MY ERROR LOG
03-15 18:26:03.150: I/Adreno200-EGLSUB(4541): <ConfigWindowMatch:2081>: Format RGBA_8888.
03-15 18:26:03.160: D/memalloc(4541): /dev/pmem: Mapped buffer base:0x519b7000 size:3010560 offset:2396160 fd:66
03-15 18:26:03.610: D/CameraConfigurationManager(4541): Default preview format: 17/yuv420sp
03-15 18:26:03.610: D/CameraConfigurationManager(4541): Screen resolution: Point(480, 320)
03-15 18:26:03.610: D/CameraConfigurationManager(4541): preview-size-values parameter: 640x480,640x368,512x288,384x288,352x288,320x240,176x144
03-15 18:26:03.610: D/CameraConfigurationManager(4541): Camera resolution: Point(512, 288)
03-15 18:26:03.620: D/CameraConfigurationManager(4541): Setting preview size: Point(512, 288)
03-15 18:26:03.780: D/CameraManager(4541): Calculated framing rect: Rect(60, 40 - 420, 280)
03-15 18:26:03.900: D/memalloc(4541): /dev/pmem: Mapped buffer base:0x51f16000 size:6184960 offset:5570560 fd:72
03-15 18:26:04.100: D/memalloc(4541): /dev/pmem: Mapped buffer base:0x525fc000 size:1843200 offset:1228800 fd:75
03-15 18:26:05.140: D/-heap(4541): GC_FOR_ALLOC freed 1322K, 22% free 6798K/8611K, paused 82ms
03-15 18:26:06.340: D/DecodeHandler(4541): Found barcode in 267 ms
03-15 18:26:06.360: D/-heap(4541): GC_FOR_ALLOC freed 1363K, 24% free 6817K/8867K, paused 19ms
03-15 18:26:06.380: D/CaptureActivityHandler(4541): Got decode succeeded message
03-15 18:26:06.530: D/MediaPlayer(4541): start() mUri is null
03-15 18:26:08.510: W/dalvikvm(4541): threadid=1: thread exiting with uncaught exception (group=0x40af39f0)
03-15 18:26:08.520: E/AndroidRuntime(4541): FATAL EXCEPTION: main
03-15 18:26:08.520: E/AndroidRuntime(4541): java.lang.NullPointerException
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.view.ViewConfiguration.get(ViewConfiguration.java:333)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.view.View.<init>(View.java:2711)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.view.View.<init>(View.java:2757)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.view.ViewGroup.<init>(ViewGroup.java:419)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:52)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.webkit.WebView.<init>(WebView.java:1092)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.webkit.WebView.<init>(WebView.java:1075)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.webkit.WebView.<init>(WebView.java:1064)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.webkit.WebView.<init>(WebView.java:1054)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.webkit.WebView.<init>(WebView.java:1045)
03-15 18:26:08.520: E/AndroidRuntime(4541): at com.google.zxing.client.android.result.URIResultHandler.handleButtonPress(URIResultHandler.java:146)
03-15 18:26:08.520: E/AndroidRuntime(4541): at com.google.zxing.client.android.result.ResultButtonListener.onClick(ResultButtonListener.java:38)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.view.View.performClick(View.java:3528)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.view.View$PerformClick.run(View.java:14235)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.os.Handler.handleCallback(Handler.java:605)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.os.Handler.dispatchMessage(Handler.java:92)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.os.Looper.loop(Looper.java:137)
03-15 18:26:08.520: E/AndroidRuntime(4541): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-15 18:26:08.520: E/AndroidRuntime(4541): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 18:26:08.520: E/AndroidRuntime(4541): at java.lang.reflect.Method.invoke(Method.java:511)
03-15 18:26:08.520: E/AndroidRuntime(4541): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
03-15 18:26:08.520: E/AndroidRuntime(4541): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
03-15 18:26:08.520: E/AndroidRuntime(4541): at dalvik.system.NativeStart.main(Native Method)

Your WebView is flowing in air. Attach it to view hierarchy before doing anything or create webview via xml layout.

Related

Android error: application has stopped unexpectedly. Please try again"

there is no error in application but when running it in android emulator I get a sorry message saying my application "has stopped unexpectedly. Please try again".I'm new in android and don't know what is wrong. Please help me.
Logcat is as follows:
06-10 16:55:38.587: D/szipinf(460): Initializing inflate state
06-10 16:55:45.569: D/szipinf(460): Initializing inflate state
06-10 16:55:48.497: D/szipinf(460): Initializing inflate state
06-10 16:55:51.207: I/dalvikvm(460): Jit: resizing JitTable from 512 to 1024
06-10 16:55:53.140: D/szipinf(460): Initializing inflate state
06-10 16:56:02.108: D/AndroidRuntime(460): Shutting down VM
06-10 16:56:02.108: W/dalvikvm(460): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-10 16:56:02.188: E/AndroidRuntime(460): FATAL EXCEPTION: main
06-10 16:56:02.188: E/AndroidRuntime(460): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.uvwxy.footpath/de.uvwxy.footpath.gui.Loader}: java.lang.StringIndexOutOfBoundsException
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.os.Looper.loop(Looper.java:123)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-10 16:56:02.188: E/AndroidRuntime(460): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 16:56:02.188: E/AndroidRuntime(460): at java.lang.reflect.Method.invoke(Method.java:507)
06-10 16:56:02.188: E/AndroidRuntime(460): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-10 16:56:02.188: E/AndroidRuntime(460): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-10 16:56:02.188: E/AndroidRuntime(460): at dalvik.system.NativeStart.main(Native Method)
06-10 16:56:02.188: E/AndroidRuntime(460): Caused by: java.lang.StringIndexOutOfBoundsException
06-10 16:56:02.188: E/AndroidRuntime(460): at java.lang.String.substring(String.java:1651)
06-10 16:56:02.188: E/AndroidRuntime(460): at de.uvwxy.footpath.gui.Loader.onCreate(Loader.java:231)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-10 16:56:02.188: E/AndroidRuntime(460): ... 11 more
06-10 16:56:12.558: I/Process(460): Sending signal. PID: 460 SIG: 9
As you can tell by reading the stack trace, you have a StringIndexOutOfBoundsException, stemming from line 231 of your de.uvwxy.footpath.gui.Loader class, in its onCreate() method.
You're getting a StringIndexOutOfBoundsException in the Loader.java class at line 231. Check the substringing you're doing at that line.

greenDAO testSuiteConstructionFailed error when testing entities

I have tried writing test cases in JUnit using the greenDAO sample app as an example, but I get a RuntimeException caused by InvocationTargetException:
It doesn't even run the tests.
Below is the code that is barfing this up:
import de.greenrobot.dao.test.*;
public class LibrarySummaryTest extends AbstractDaoTestLongPk<LibrarySummaryDao, LibrarySummary> {
public LibrarySummaryTest() {
super(LibrarySummaryDao.class);
}
#Override
protected LibrarySummary createEntity(Long arg0) {
// TODO Auto-generated method stub
return null;
}
}
Is there something I am missing?
I have an Android app, the tests are in a separate app. I indicated this when I generated the code:
schema.setDefaultJavaPackageTest("com.ralphpina.greenDao.test");
schema.setDefaultJavaPackageDao("com.ralphpina.greenDao.greendao");
I have the instrumentation correctly targeting the app. I have a whole bunch of JUnit test cases that run perfectly fine.
I have included the greenDAO.jar in both apps, and I have double checked that it is in the build path.
I have the notes sample app in my eclipse environment and the JUnit test runs fine there. So there must be something specific in my project. Any suggestions?
Text of full exception:
03-15 01:02:22.794: I/TestRunner(8775): java.lang.RuntimeException: Exception during suite construction
03-15 01:02:22.794: I/TestRunner(8775): at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
03-15 01:02:22.794: I/TestRunner(8775): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 01:02:22.794: I/TestRunner(8775): at java.lang.reflect.Method.invoke(Method.java:511)
03-15 01:02:22.794: I/TestRunner(8775): at junit.framework.TestCase.runTest(TestCase.java:168)
03-15 01:02:22.794: I/TestRunner(8775): at junit.framework.TestCase.runBare(TestCase.java:134)
03-15 01:02:22.794: I/TestRunner(8775): at junit.framework.TestResult$1.protect(TestResult.java:115)
03-15 01:02:22.794: I/TestRunner(8775): at junit.framework.TestResult.runProtected(TestResult.java:133)
03-15 01:02:22.794: I/TestRunner(8775): at junit.framework.TestResult.run(TestResult.java:118)
03-15 01:02:22.794: I/TestRunner(8775): at junit.framework.TestCase.run(TestCase.java:124)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
03-15 01:02:22.794: I/TestRunner(8775): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
03-15 01:02:22.794: I/TestRunner(8775): Caused by: java.lang.reflect.InvocationTargetException
03-15 01:02:22.794: I/TestRunner(8775): at java.lang.reflect.Constructor.constructNative(Native Method)
03-15 01:02:22.794: I/TestRunner(8775): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)
03-15 01:02:22.794: I/TestRunner(8775): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379)
03-15 01:02:22.794: I/TestRunner(8775): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
03-15 01:02:22.794: I/TestRunner(8775): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
03-15 01:02:22.794: I/TestRunner(8775): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
03-15 01:02:22.794: I/TestRunner(8775): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 01:02:22.794: I/TestRunner(8775): at android.os.Looper.loop(Looper.java:137)
03-15 01:02:22.794: I/TestRunner(8775): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-15 01:02:22.794: I/TestRunner(8775): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 01:02:22.794: I/TestRunner(8775): at java.lang.reflect.Method.invoke(Method.java:511)
03-15 01:02:22.794: I/TestRunner(8775): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-15 01:02:22.794: I/TestRunner(8775): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-15 01:02:22.794: I/TestRunner(8775): at dalvik.system.NativeStart.main(Native Method)
03-15 01:02:22.794: I/TestRunner(8775): Caused by: java.lang.NoClassDefFoundError: com.outridersw.tapinspectandroid.greendao.DaoMaster
03-15 01:02:22.794: I/TestRunner(8775): at com.outridersw.tapinspectandroid.test.LibrarySummaryTest.<init>(LibrarySummaryTest.java:13)
03-15 01:02:22.794: I/TestRunner(8775): ... 18 more
Update:
I was able to run JUnit by copying and pasting the generated classes in greenDAO into my test project. Obviously, this is not ideal, since now I have to remember to update them. Is there a reason JUnit can't find the greenDAO classes, but has no problems seeing all other classes in my target Android project?
It turns out the reason for this error is that I included the greenDAO.jar library in both the main and test Android projects. Once I deleted the jar from the project/libs folder I was able to run JUnit greenDAO tests without an issue!

google maps v2 android

I'm trying to set up google map on an android application.
I saw a lots of qusestions about this error but no one realy answer to my prolem
My error file
03-15 22:32:56.235: D/AndroidRuntime(6713): Shutting down VM
03-15 22:32:56.235: W/dalvikvm(6713): threadid=1: thread exiting with uncaught exception (group=0x415b22a0)
03-15 22:32:56.235: E/AndroidRuntime(6713): FATAL EXCEPTION: main
03-15 22:32:56.235: E/AndroidRuntime(6713): java.lang.RuntimeException: Unable to start activity ComponentInfo{ant.project.myway/ant.project.myway.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.os.Looper.loop(Looper.java:137)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.ActivityThread.main(ActivityThread.java:4895)
03-15 22:32:56.235: E/AndroidRuntime(6713): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 22:32:56.235: E/AndroidRuntime(6713): at java.lang.reflect.Method.invoke(Method.java:511)
03-15 22:32:56.235: E/AndroidRuntime(6713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-15 22:32:56.235: E/AndroidRuntime(6713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-15 22:32:56.235: E/AndroidRuntime(6713): at dalvik.system.NativeStart.main(Native Method)
03-15 22:32:56.235: E/AndroidRuntime(6713): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-15 22:32:56.235: E/AndroidRuntime(6713): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.Activity.setContentView(Activity.java:1912)
03-15 22:32:56.235: E/AndroidRuntime(6713): at ant.project.myway.MainActivity.onCreate(MainActivity.java:11)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.Activity.performCreate(Activity.java:5163)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
03-15 22:32:56.235: E/AndroidRuntime(6713): ... 11 more
03-15 22:32:56.235: E/AndroidRuntime(6713): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-15 22:32:56.235: E/AndroidRuntime(6713): ... 21 more
03-15 22:32:56.235: E/AndroidRuntime(6713): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
03-15 22:32:56.235: E/AndroidRuntime(6713): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-15 22:32:56.235: E/AndroidRuntime(6713): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-15 22:32:56.235: E/AndroidRuntime(6713): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-15 22:32:56.235: E/AndroidRuntime(6713): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
03-15 22:32:56.235: E/AndroidRuntime(6713): ... 24 more
03-15 22:36:00.345: I/Process(6713): Sending signal. PID: 6713 SIG: 9
So this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ant.project.myway"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="ant.project.myway.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="ant.project.myway.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/api_key"/>
</application>
</manifest>
My activity
package ant.project.myway;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
And the layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</RelativeLayout>
I saw a lots of posts to correct this problem,
I'm not sure my api key is correct, I'm on ubuntu.
I go to ~/.android, I run
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android
I got my key and I set my_key;ant.project.myway on google console api key
I think this is the correct way
Thanks for your help
The problem you are experiencing is not related to your key in any way, from you logcat output:
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
Basically means that at the moment that your layout was instantiated, SupportMapFragment class was not found. what leads me to think that you have a problem with the way you are referencing the google-play-services library.
You can take a look my blog post on how to add a Google map in your application to find more information.
If you have generate key with the help of "ant.project.myway" packeage naem then you should use only this package name in the permission tag.
Please try this...
<permission
android:name="ant.project.myway.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
Also use android:name instead of class attribute
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
Also add this permission in your manifest
<uses-permission android:name="ant.project.myway.permission.MAPS_RECEIVE" />
Add this in your activity:
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

Inflate Error on Google Maps v2

I try to add a Google Map to my application and using this tutorial I generated API code, added all necessary meta data, permissions etc. Whenever i click the button to start a new activity the app crashes on my Galaxy S3
onClickListener
Button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (v == Button) {
startActivity(new Intent(MainActivity.this, ShowMap.class));
}
}
});
Map class
public class ShowMap extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_map);
}
}
show_map.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Error
03-15 20:14:51.825: E/AndroidRuntime(18318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appname.subappname/com.appname.subappname.ShowMap}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.os.Looper.loop(Looper.java:137)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-15 20:14:51.825: E/AndroidRuntime(18318): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 20:14:51.825: E/AndroidRuntime(18318): at java.lang.reflect.Method.invoke(Method.java:511)
03-15 20:14:51.825: E/AndroidRuntime(18318): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-15 20:14:51.825: E/AndroidRuntime(18318): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-15 20:14:51.825: E/AndroidRuntime(18318): at dalvik.system.NativeStart.main(Native Method)
03-15 20:14:51.825: E/AndroidRuntime(18318): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-15 20:14:51.825: E/AndroidRuntime(18318): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.Activity.setContentView(Activity.java:1924)
03-15 20:14:51.825: E/AndroidRuntime(18318): at com.appname.subappname.ShowMap.onCreate(ShowMap.java:11)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.Activity.performCreate(Activity.java:5206)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-15 20:14:51.825: E/AndroidRuntime(18318): ... 11 more
03-15 20:14:51.825: E/AndroidRuntime(18318): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
03-15 20:14:51.825: E/AndroidRuntime(18318): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-15 20:14:51.825: E/AndroidRuntime(18318): ... 20 more
The class com.google.android.gms.maps.MapFragment is not found. Check if library google-play-services_lib is properly linked to the project.
your ShowMap should extends FragmentActivity for this to work not Activity , check the examples included in google-play-sevice library for google maps they are a big help.
Edit
make sure you are including google-play-service library project, as the exception is ClassNotFoundException: com.google.android.gms.maps.MapFragment
check this link on how to include the library project

Getting an error while passing arraylist through intent

Hi I am new to android any one help me out from this error...
my code looks like
wheelArrayList = (ArrayList<String>) bundle.get("listData");
Logcat:
03-15 18:29:54.967: E/AndroidRuntime(527): FATAL EXCEPTION: main
03-15 18:29:54.967: E/AndroidRuntime(527): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pack.customadpterforendless/com.pack.customadpterforendless.MainActivity}: java.lang.ClassCastException: java.lang.String
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.os.Looper.loop(Looper.java:123)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-15 18:29:54.967: E/AndroidRuntime(527): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 18:29:54.967: E/AndroidRuntime(527): at java.lang.reflect.Method.invoke(Method.java:521)
03-15 18:29:54.967: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-15 18:29:54.967: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-15 18:29:54.967: E/AndroidRuntime(527): at dalvik.system.NativeStart.main(Native Method)
03-15 18:29:54.967: E/AndroidRuntime(527): Caused by: java.lang.ClassCastException: java.lang.String
03-15 18:29:54.967: E/AndroidRuntime(527): at com.pack.customadpterforendless.MainActivity.onCreate(MainActivity.java:42)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-15 18:29:54.967: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-15 18:29:54.967: E/AndroidRuntime(527): ... 11 more
You should use
getIntent().getXXXArrayListExtra("Name");
Where XXX represents the type of objects what ArraList contains, For Example if your ArrayList is a list of Strings, then use
getIntent().getStringArrayListExtra("Name");

Categories

Resources