ClassNotFoundException - connectiong to MSSQL Database - android

I want to connect my android application to my MSSQL Database.
Unfortunately, there is a problem :/
10-25 19:17:00.536: W/System.err(18961): java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
10-25 19:17:00.546: W/System.err(18961): at java.lang.Class.classForName(Native Method)
10-25 19:17:00.556: W/System.err(18961): at java.lang.Class.forName(Class.java:217)
10-25 19:17:00.556: W/System.err(18961): at java.lang.Class.forName(Class.java:172)
10-25 19:17:00.556: W/System.err(18961): at com.example.mssqlcon.MainActivity.onCreate(MainActivity.java:21)
10-25 19:17:00.556: W/System.err(18961): at android.app.Activity.performCreate(Activity.java:4465)
10-25 19:17:00.556: W/System.err(18961): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread.access$600(ActivityThread.java:132)
10-25 19:17:00.556: W/System.err(18961): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
10-25 19:17:00.556: W/System.err(18961): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 19:17:00.556: W/System.err(18961): at android.os.Looper.loop(Looper.java:137)
10-25 19:17:00.566: W/System.err(18961): at android.app.ActivityThread.main(ActivityThread.java:4575)
10-25 19:17:00.566: W/System.err(18961): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 19:17:00.566: W/System.err(18961): at java.lang.reflect.Method.invoke(Method.java:511)
10-25 19:17:00.566: W/System.err(18961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-25 19:17:00.566: W/System.err(18961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-25 19:17:00.566: W/System.err(18961): at dalvik.system.NativeStart.main(Native Method)
10-25 19:17:00.566: W/System.err(18961): Caused by: java.lang.NoClassDefFoundError: net/sourceforge/jtds/jdbc/Driver
10-25 19:17:00.566: W/System.err(18961): ... 18 more
10-25 19:17:00.566: W/System.err(18961): Caused by: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
10-25 19:17:00.576: W/System.err(18961): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-25 19:17:00.576: W/System.err(18961): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-25 19:17:00.576: W/System.err(18961): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-25 19:17:00.576: W/System.err(18961): ... 18 more
My code:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(
"jdbc:jtds:sqlserver://ip_of_my_database", "*****", "*******");
Statement statement = connection.createStatement();
//ResultSet result = statement
// .executeQuery("SELECT * FROM nazwatabeli");
ResultSet result = statement.executeQuery("SELECT * FROM name");
if(result.first()){
do{
Log.v("MainActivity", "Name: "+result.getString(result.getRow()));
} while(result.next());
}
} catch (Exception e){
e.printStackTrace();
}
}
}
What I do wrong?

You can't access SQL server directly using the Android device. You have to use a kind of a webservice to gain the access to a server which have the SQL connected. You can use java or php to do this. Check the following link for java webservices with android.
http://sarangasl.blogspot.com/2011/10/android-web-service-access-tutorial.html
What is the SDK version you are using? If it is r20 or upper you have to include all the external library files which you are using to lib folder inside the project through out your project. Otherwise it will tell ClassNotFoundException.
Tell me if you want any clarification.

Related

Throw exception when update android support dependencies: RuntimeException: Unable to bind views for

I'm developing an app that uses:
compileSdkVersion 23
buildToolsVersion "23.0.1"
My code works correctly with the following dependencies (23.0.1):
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
I want to update to (23.1.0):
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
Note: If android studio gives me an exception, before Sync Gradle I go to following menu
Menu/build/Clean Project
Error: When run app on device this gives the following exception:
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: FATAL EXCEPTION: main
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.perdidos.syp.objetosperdidos/com.perdidos.syp.objetosperdidos.DrawerBaseActivity}: java.lang.RuntimeException: Unable to bind views for com.perdidos.syp.objetosperdidos.DrawerBaseActivity
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:165)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.os.Looper.loop(Looper.java:194)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5370)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: Caused by: java.lang.RuntimeException: Unable to bind views for com.perdidos.syp.objetosperdidos.DrawerBaseActivity
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at butterknife.ButterKnife.bind(ButterKnife.java:322)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at butterknife.ButterKnife.bind(ButterKnife.java:237)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.perdidos.syp.objetosperdidos.DrawerBaseActivity.onCreate(DrawerBaseActivity.java:131)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5122)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:165)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.os.Looper.loop(Looper.java:194)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5370)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: Caused by: java.lang.IllegalStateException: Required view 'imageCover' with ID 2131689711 for field 'mImageCover' was not found. If this view is optional add '#Nullable' annotation.
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.perdidos.syp.objetosperdidos.DrawerBaseActivity$$ViewBinder.bind(DrawerBaseActivity$$ViewBinder.java:18)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.perdidos.syp.objetosperdidos.DrawerBaseActivity$$ViewBinder.bind(DrawerBaseActivity$$ViewBinder.java:9)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at butterknife.ButterKnife.bind(ButterKnife.java:319)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at butterknife.ButterKnife.bind(ButterKnife.java:237)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.perdidos.syp.objetosperdidos.DrawerBaseActivity.onCreate(DrawerBaseActivity.java:131)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5122)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:165)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.os.Looper.loop(Looper.java:194)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5370)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-25 20:08:39.056 1817-1817/com.perdidos.syp.objetosperdidos E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
Question: Do I have to wait for the library is updated butterknife?

Unable to start activity NullPointerException-onActivityCreated

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

Getting error while running android app (Unable to find explicit activity class) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
10-25 05:30:06.560: W/dalvikvm(1428): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
10-25 05:30:06.670: E/AndroidRuntime(1428): FATAL EXCEPTION: main
10-25 05:30:06.670: E/AndroidRuntime(1428): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidhiv/com.example.androidhiv.AllProductsActivity}; have you declared this activity in your AndroidManifest.xml?
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.Activity.startActivityForResult(Activity.java:3370)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.Activity.startActivityForResult(Activity.java:3331)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.Activity.startActivity(Activity.java:3566)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.Activity.startActivity(Activity.java:3534)
10-25 05:30:06.670: E/AndroidRuntime(1428): at com.example.androidhiv.MainScreenActivity$1.onClick(MainScreenActivity.java:31)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.view.View.performClick(View.java:4204)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.view.View$PerformClick.run(View.java:17355)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.os.Handler.handleCallback(Handler.java:725)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.os.Looper.loop(Looper.java:137)
10-25 05:30:06.670: E/AndroidRuntime(1428): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-25 05:30:06.670: E/AndroidRuntime(1428): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 05:30:06.670: E/AndroidRuntime(1428): at java.lang.reflect.Method.invoke(Method.java:511)
10-25 05:30:06.670: E/AndroidRuntime(1428): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-25 05:30:06.670: E/AndroidRuntime(1428): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-25 05:30:06.670: E/AndroidRuntime(1428): at dalvik.system.NativeStart.main(Native Method)
Make sure that this Activity is register in Android Manifeast
You have not declared your Activity AllProductsActivity in your manifest file and the compiler is unable to find that Activity hence throwing error.
Declare Activity AllProductsActivity in your manifest file.
like this
<activity android:name="com.example.androidhiv.AllProductsActivity"
></activity>
Its showing that you have not declared your AllProductsActivity in your manifest file.
<activity
android:name="com.example.androidhiv.AllProductsActivity"
/>
You had to declare each and every Acticity which you want to show in your application it had to be declare in AndroidManifest.xml file.
<activity android:name="com.example.androidhiv.AllProductsActivity" />

After opening PDF with intent, app crashes with NullPointerException

I have a app that shows a ListView with several documents (DOC, PDF, PPT...). Selection one of them, I use the following code to show the document:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(outFile).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (extension.equalsIgnoreCase("") || mimetype == null) {
intent.setDataAndType(Uri.fromFile(outFile), "text/*");
} else {
intent.setDataAndType(Uri.fromFile(outFile), mimetype);
}
startActivity(Intent.createChooser(intent, "Choose an Application:"));
That works fine for the the first document selected, Polaris Office opens and show the document - fine. When switching back for selecting the next document, my application is not on the last screen shown, instead it starts again. Selecting the document works and open fine in Polaris. When now switching back, the app crashes with Unable to start activity ...MainActivity ... NullPointerExpetion.
What can I do to solve this problem?
Here the LogCat:
10-25 10:07:43.476: D/AndroidRuntime(8396): Shutting down VM
10-25 10:07:43.476: W/dalvikvm(8396): threadid=1: thread exiting with uncaught exception (group=0x415092a0)
10-25 10:07:43.507: E/AndroidRuntime(8396): FATAL EXCEPTION: main
10-25 10:07:43.507: E/AndroidRuntime(8396): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.astrex.ppastrex/com.astrex.ppastrex.MainActivity}: java.lang.NullPointerException
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.os.Looper.loop(Looper.java:137)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.main(ActivityThread.java:4895)
10-25 10:07:43.507: E/AndroidRuntime(8396): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 10:07:43.507: E/AndroidRuntime(8396): at java.lang.reflect.Method.invoke(Method.java:511)
10-25 10:07:43.507: E/AndroidRuntime(8396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
10-25 10:07:43.507: E/AndroidRuntime(8396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
10-25 10:07:43.507: E/AndroidRuntime(8396): at dalvik.system.NativeStart.main(Native Method)
10-25 10:07:43.507: E/AndroidRuntime(8396): Caused by: java.lang.NullPointerException
10-25 10:07:43.507: E/AndroidRuntime(8396): at com.astrex.ppastrex.FrameDocumentos.onCreateView(FrameDocumentos.java:66)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.Activity.performStart(Activity.java:5173)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
10-25 10:07:43.507: E/AndroidRuntime(8396): ... 11 more
I had a similar issue happening for me on Android 6.0, but not in 4.4, so for older devices, it would work fine and there would be no crash.
In my case, I was downloading a url, saving the file and opening them in 3rd party viewers.
I've discovered that as long as I save the pdf to the Downloads Directory, it fixes it for my situation.
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File dir = new File(root.getAbsolutePath());
if (dir.exists() == false) {
dir.mkdirs();
}
String fileName = "filename.pdf";
file = new File(dir, fileName);
try like this:
File file = new File(pdfpath);
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
finish();
}
catch (ActivityNotFoundException e) {
}
}
The intent looks like it was called correctly it works for some. Seems like you'd have a null reference without checking if the file exists.
Experience tells me the null comes because your device ran out of memory while opening the pdf file so your app was shut down to free up some memory.
The solution is to add the savedinstancestate method saving what your app needs and check if the savedinstancestate != null in your oncreate method then recreate what your app needs from the savedinstancestate.

admob -> ad network mediation with adfonic

I am getting error while using adfonic in admob. i am getting following error.
Cannot find adapter class 'com.google.ads.mediation.adfonic.AdfonicAdapter'. Did you link the ad network's mediation adapter? Skipping ad network.
detailed exception is bellow.
Cannot find adapter class 'com.google.ads.mediation.adfonic.AdfonicAdapter'. Did you link the ad network's mediation adapter? Skipping ad network.
The following was caught and handled:
java.lang.ClassNotFoundException: com.google.ads.mediation.adfonic.AdfonicAdapter
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at com.google.ads.g.a(SourceFile:133)
at com.google.ads.i.run(SourceFile:116)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
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:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com/google/ads/mediation/adfonic/AdfonicAdapter
... 14 more
Caused by: java.lang.ClassNotFoundException: com.google.ads.mediation.adfonic.AdfonicAdapter
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 14 more Cannot find adapter class 'com.google.ads.mediation.adfonic.AdfonicAdapter'. Did you link the ad network's mediation adapter? Skipping ad network.
The following was caught and handled:
java.lang.ClassNotFoundException: com.google.ads.mediation.adfonic.AdfonicAdapter
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at com.google.ads.g.a(SourceFile:133)
at com.google.ads.i.run(SourceFile:116)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
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:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com/google/ads/mediation/adfonic/AdfonicAdapter
... 14 more
Caused by: java.lang.ClassNotFoundException: com.google.ads.mediation.adfonic.AdfonicAdapter
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 14 more
You haven't included the Adfonic mediation adapter in your app. Include that and it will work.

Categories

Resources