class not found and null object reference exception out of nowhere - android

I have now completed all the scripting and designing with no compile time error but out of no where this run time error comes in and my app flashes away and do not get launched.
I have got all the files that it requires and everything done,
Please suggest now,
This is my MainActivity.java code thats probably throwing these exceptions
package com.example.dell.demologin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.HashMap;
import activity.LoginActivity;
import helper.SQLiteHandler;
import helper.SessionManager;
public class MainActivity extends Activity {
private TextView txtName;
private TextView txtEmail;
private Button btnLogout;
private SQLiteHandler db;
private SessionManager session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
txtName = (TextView) findViewById(R.id.name);
txtEmail = (TextView) findViewById(R.id.email);
btnLogout = (Button) findViewById(R.id.btnLogout);
// SqLite database handler
db = new SQLiteHandler(getApplicationContext());
// session manager
session = new SessionManager(getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from sqlite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
String email = user.get("email");
// Displaying the user details on the screen
txtName.setText(name);
txtEmail.setText(email);
// Logout button click event
btnLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
logoutUser();
}
});
}
/**
* Logging out the user. Will set isLoggedIn flag to false in shared
* preferences Clears the user data from sqlite users table
* */
private void logoutUser() {
session.setLogin(false);
db.deleteUsers();
// Launching the login activity
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}
This is my logcat,
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dell.demologin, PID: 15578
java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
at android.app.LoadedApk.makeApplication(LoadedApk.java:601)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757)
at android.app.ActivityThread.access$1600(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5507)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:220)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
at android.app.Application.attach(Application.java:187)
at android.app.Instrumentation.newApplication(Instrumentation.java:1001)
at android.app.Instrumentation.newApplication(Instrumentation.java:985)
at android.app.LoadedApk.makeApplication(LoadedApk.java:586)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5507) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at java.lang.Class.forName(Class.java:285)
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
at android.app.Application.attach(Application.java:187) 
at android.app.Instrumentation.newApplication(Instrumentation.java:1001) 
at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
at android.app.LoadedApk.makeApplication(LoadedApk.java:586) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5507) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.demologin.AppController" on path: DexPathList[[zip file "/data/app/com.example.dell.demologin-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dell.demologin-2/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:324) 
at java.lang.Class.forName(Class.java:285) 
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209) 
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
at android.app.Application.attach(Application.java:187) 
at android.app.Instrumentation.newApplication(Instrumentation.java:1001) 
at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
at android.app.LoadedApk.makeApplication(LoadedApk.java:586) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5507) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.demologin.AppController" on path: DexPathList[[dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-support-annotations-23.4.0_2f85958e3577c0887206665b958d529f2917b10d-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-mysql-connector-java_910883ba1d0637ad761451367a22e76261a44141-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-jtds_dd6bef0a517729fc55f6897f784dfc3379233a03-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-internal_impl-23.4.0_acbefc0422230ccc1164ab
E/AndroidRuntime: Error reporting crash
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Application.getApplicationContext()' on a null object reference
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:96)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
I/Process: Sending signal. PID: 15578 SIG: 9
Application terminated.

Known bug in the Google Play store upgrade process, https://code.google.com/p/android/issues/detail?id=56296

Related

how to resolve java.lang.InstantiationException android?

I am learning android programming. thank you for your help.
the last time i run my app in android studio, it run completely and without errors. the next day i run the app did not give any error but the program did not run and showed in the emulator: "unfortunately, My Application1 has stopped" and in the run part in android studio i encountered these cases:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication1, PID: 1701
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myapplication1/com.example.myapplication1.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.example.myapplication1.MainActivity> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.InstantiationException: java.lang.Class<com.example.myapplication1.MainActivity> cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
its code:
package com.example.myapplication1;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public abstract class MainActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher {
private static final String TAG= "MainActivity";
Button btn1, btn2;
ImageView imageView;
#SuppressLint("ResourceAsColor")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=findViewById(R.id.firstButton);
btn2=findViewById(R.id.secondButton);
imageView=findViewById(R.id.imageView);
btn1.setText(R.string.btn);
btn1.setTextColor(getResources().getColor(R.color.purple_700));
btn1.setBackgroundColor(getResources().getColor(R.color.teal_700));
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d(TAG, "click btn1");
}
});
btn2.setOnClickListener(this);
imageView.setScaleType(ImageView.ScaleType.FIT_START);
Toast.makeText(this,"salam",Toast.LENGTH_SHORT).show();
}
#Override
public void onClick(View v) {
Log.d(TAG, "click btn2");
}
}
where is the problem and is there a solution?

Couldn't use getRefrence() with firebase in android

iv'e been stuck for hours trying to figure out what's the problem...
every time I try to access the reference the up crushes.
tried to open like 5 new projects and firebases....
MainActivity( only realated stuff):
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button ba;
FirebaseDatabase database;
DatabaseReference myRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ba=findViewById(R.id.ba);
ba.setOnClickListener(this);
}
#Override
public void onClick(View view) {
if(view==ba)
{
database = FirebaseDatabase.getInstance();
myRef=database.getReference("Foods"); //this is where it crushes
// myRef.setValue("ba");
}
}
}
The Run Log:
E/RunLoop: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client#google.com
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;
at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:112)
at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:246)
at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database##16.0.4:98)
at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database##16.0.4:77)
at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database##16.0.4:92)
at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database##16.0.4:42)
at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database##16.0.4:357)
at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database##16.0.4:201)
at com.example.caloriccalcyair1.MainActivity.onClick(MainActivity.java:43)
at android.view.View.performClick(View.java:7869)
at android.widget.TextView.performClick(TextView.java:14958)
at android.view.View.performClickInternal(View.java:7838)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29362)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8016)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListener" on path: DexPathList[[zip file "/data/app/com.example.caloriccalcyair1-mv4wi0pKnsqKEHcy89c_hA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.caloriccalcyair1-mv4wi0pKnsqKEHcy89c_hA==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:112) 
at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:246) 
at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database##16.0.4:98) 
at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database##16.0.4:77) 
at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database##16.0.4:92) 
at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database##16.0.4:42) 
at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database##16.0.4:357) 
at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database##16.0.4:201) 
at com.example.caloriccalcyair1.MainActivity.onClick(MainActivity.java:43) 
at android.view.View.performClick(View.java:7869) 
at android.widget.TextView.performClick(TextView.java:14958) 
at android.view.View.performClickInternal(View.java:7838) 
at android.view.View.access$3600(View.java:886) 
at android.view.View$PerformClick.run(View.java:29362) 
at android.os.Handler.handleCallback(Handler.java:883) 
at android.os.Handler.dispatchMessage(Handler.java:100) 
at android.os.Looper.loop(Looper.java:237) 
at android.app.ActivityThread.main(ActivityThread.java:8016) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) 
i followed the firebase installation step by step and verifyed the project.
also added the firebase to the porject with the Tools option, so everything should be ok
image of the firebase database
Instead of using your code.
Try using this:
database = FirebaseDatabase.getInstance().getReference().child("Foods");
And also try wrapping your on click listener like this inside onCreate
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
...
}
});

I can't switch to another activity by clicking on the button? I have to simulate a multiactivity

I am reproducing a multiactivity situation where I have multiple java classes with the same code and equal xml classes with a button inside that should make me switch from one activity to another. When I run the code it gives me this type of error. Can you tell me why?
package com.example.multiactivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class Activity1 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
}
public void lanciaActivity(View v) {
Intent i = new Intent(getApplicationContext(),Activity2.class);
//Settando il seguente flag l'activity che viene lanciata non verrà salvata nel backstack!
//i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
}
}
This is the error message when I run the app.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.multiactivity, PID: 21264
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:6088)
at android.view.View.performClick(View.java:7333)
at android.widget.TextView.performClick(TextView.java:14160)
at android.view.View.performClickInternal(View.java:7299)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27773)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6986)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:6083)
at android.view.View.performClick(View.java:7333) 
at android.widget.TextView.performClick(TextView.java:14160) 
at android.view.View.performClickInternal(View.java:7299) 
at android.view.View.access$3200(View.java:846) 
at android.view.View$PerformClick.run(View.java:27773) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:6986) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445) 
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.multiactivity/com.example.multiactivity.Activity1}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2016)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
at android.app.Activity.startActivityForResult(Activity.java:4688)
at android.app.Activity.startActivityForResult(Activity.java:4646)
at android.app.Activity.startActivity(Activity.java:5007)
at android.app.Activity.startActivity(Activity.java:4975)
at com.example.multiactivity.MainActivity.lanciaActivity(MainActivity.java:19)
at java.lang.reflect.Method.invoke(Native Method) 
at android.view.View$DeclaredOnClickListener.onClick(View.java:6083) 
at android.view.View.performClick(View.java:7333) 
at android.widget.TextView.performClick(TextView.java:14160) 
at android.view.View.performClickInternal(View.java:7299) 
at android.view.View.access$3200(View.java:846) 
at android.view.View$PerformClick.run(View.java:27773) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:6986) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445) 
I/Process: Sending signal. PID: 21264 SIG: 9
Process 21264 terminated.
Activity2 is equal to Activity1, except that Activity2 launches Activity3 instead.
The xml of the button is as follows:
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:onClick="lanciaActivity"
android:text="Passa a altra Activity" />
I guess you initiated the intent improperly try added the current activity name instead of getapplicationcontext();
If you looked at the second "Caused by" in your error message, it asks at the end "have you declared this activity in your AndroidManifest.xml?" This is the problem. You have to add the activity to your AndroidManifest.xml file.
<activity android:name=".MyActivity" android:label="#string/app_name"/>
You can also add whatever properties you need under the android:label. That worked for me.

errors after importing v7 app compact

while executing the code
package com.example.swvt1;
import java.util.ArrayList;
import java.util.List;
import com.example.adapters.MyFragmentPagerAdapter;
import com.example.fragments.fragment1;
import com.example.fragments.fragment2;
import com.example.fragments.fragment3;
import com.example.fragments.fragment4;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.view_pager);
List<Fragment> listfragments = new ArrayList<Fragment>();
listfragments.add(new fragment1());
listfragments.add(new fragment2());
listfragments.add(new fragment3());
listfragments.add(new fragment4());
MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), listfragments);
viewPager.setAdapter(myFragmentPagerAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
while executing the above code i am getting the errors such as no class definition found and class not found exception and the stack trace is as follows
E/AndroidRuntime(27466): FATAL EXCEPTION: main
E/AndroidRuntime(27466): Process: com.example.swvt1, PID: 27466
E/AndroidRuntime(27466): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.swvt1/com.example.swvt1.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.swvt1.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.swvt1-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(27466):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2290)
E/AndroidRuntime(27466): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
E/AndroidRuntime(27466): at android.app.ActivityThread.access$800(ActivityThread.java:156)
E/AndroidRuntime(27466): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
E/AndroidRuntime(27466): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(27466): at android.os.Looper.loop(Looper.java:211)
E/AndroidRuntime(27466): at android.app.ActivityThread.main(ActivityThread.java:5371)
E/AndroidRuntime(27466): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27466): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(27466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
E/AndroidRuntime(27466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
E/AndroidRuntime(27466): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.swvt1.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.swvt1-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(27466): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(27466): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(27466): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(27466): at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
E/AndroidRuntime(27466): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280)
E/AndroidRuntime(27466): ... 10 more
E/AndroidRuntime(27466): Suppressed: java.lang.NoClassDefFoundError: com.example.swvt1.MainActivity
E/AndroidRuntime(27466): at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(27466): at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(27466): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(27466): at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(27466): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(27466): ... 14 more
E/AndroidRuntime(27466): Suppressed: java.lang.ClassNotFoundException: com.example.swvt1.MainActivity
E/AndroidRuntime(27466): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(27466): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(27466): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(27466): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(27466): ... 13 more
E/AndroidRuntime(27466): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
What is the error I have done and Thanks in advance
Go the "Java Build Path" -> Order and export -> check all checkboxes -> clean -> build -> run
And Make Sure that You have v7 in your Library

Cloudmine java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

I am trying to store some data using Cloudmine.
However, I got the error java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory; when I call initialize() for authorization.
I'm not running on a separate thread or something. I'm testing stuff out right now so I just have it so that when a button is clicked, it uploads some information from some EditText fields.
This is my code
public class ButtonClick implements View.OnClickListener {
private MainWindowActivity mainWindowActivity;
public ButtonClick(MainWindowActivity mainWindowActivity, Button doneBtn, Button addBtn) {
this.mainWindowActivity = mainWindowActivity;
addBtn.setEnabled(true);
addBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// This will initialize your credentials
// ERROR HERE
CMApiCredentials initialize = CMApiCredentials.initialize("id", "key");
SimpleCMObject location = new SimpleCMObject();
location.add("address", Runner.getAddressStr());
location.add("city", Runner.getCityStr());
location.add("state", Runner.getStateStr());
location.add("zip", Runner.getZipStr());
location.save(new ObjectModificationResponseCallback() {
public void onCompletion(ObjectModificationResponse response) {
Toast.makeText(mainWindowActivity, "Location saved: " + response.wasSuccess(), Toast.LENGTH_SHORT).show();
}
});
EditText address = (EditText) mainWindowActivity.findViewById(R.id.address);
address.setText("");
EditText city = (EditText) mainWindowActivity.findViewById(R.id.city);
city.setText("");
EditText state = (EditText) mainWindowActivity.findViewById(R.id.state);
state.setText("");
EditText zip = (EditText) mainWindowActivity.findViewById(R.id.zip);
zip.setText("");
}
}
This is the Logcat:
Process: prog, PID: 26580
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/data/app/prog-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
            at prog.ButtonClick.onClick(ButtonClick.java:52)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
As I have commented, download zip file from SLF4J distribution and use as library in your project. Then, use slf4j-api-1.7.12.jar (and slf4j-android-1.7.12.jar if needed).
I had the same error and found this solution on github.
Just add the following to your grandle:
implementation 'org.slf4j:slf4j-api:1.7.25'
https://github.com/nomis/slf4j-android
I hade the same problem only on Android 5.0 - 5.1 (a real device and emulators). At that moment, I used Android Studio 2.3.3 and build tools v26.
I solved the problem turning off Instant Run that I didn't use anyway.
Steps:
go to File -> Settings -> Build, Execution, Deployment -> Instant run
Disable it (first checkbox).

Categories

Resources