Unfortunately, the application has stopped working in the Android studio
source link: https://www.codesd.com/item/unfortunately-the-application-has-stopped-working-in-the-android-studio.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Unfortunately, the application has stopped working in the Android studio
When i run the application, the emulator starts up and a message is displayed 'Unfortunately MyApplicationin stopped working.' The same message appears when the app icon is clicked. I even killed and restarted the adb server. But the error persists. Please help! This is code of MainActivity.java
> package com.computer.om.myapplicationin;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.util.ArrayMap;
public class MainActivity extends AppCompatActivity
{
int NoOfSubjects;
int i;
// int TotMarksTH[]=new int[10];
// int TotMarksPR[]=new int[10];
// int ObtMarksTH[]=new int[10];
// int ObtMarksPR[]=new int[10];
TextView Theory =
(TextView) findViewById(R.id.Theory);
TextView TheoryMarks =
(TextView) findViewById(R.id.TheoryMarks);
TextView Practical =
(TextView) findViewById(R.id.Practical);
TextView PracticalMarks =
(TextView) findViewById(R.id.PracticalMarks);
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button) findViewById(R.id.button1);
final Button button2 = (Button) findViewById(R.id.button2);
Theory.setVisibility(View.VISIBLE);
TheoryMarks.setVisibility(View.VISIBLE);
Practical.setVisibility(View.VISIBLE);
PracticalMarks.setVisibility(View.VISIBLE);
button1.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
TextView NoSubject =
(TextView) findViewById(R.id.NoSubject);
//Copying the entererd number of subjects to character sequence and then converting it to integer
// CharSequence s=NoSubject.getText();
// NoOfSubjects=Integer.parseInt(s.toString());
button2.setVisibility(View.VISIBLE);
//the label number of subjects and the enter number will get visible when we click ok button
// NoSubject.setVisibility(View.INVISIBLE);
// TextView labelsubject =
// (TextView) findViewById(R.id.NoOfSubjectslbl);
// labelsubject.setVisibility(View.INVISIBLE);
}
}
);
/* button2.setOnClickListener(
new Button.OnClickListener()
{
public void onClick(View v1)
{
CharSequence totth,totpr,obtph,obtpr;
if(i<NoOfSubjects)
{
totth=Theory.getText();
TotMarksTH[i]=Integer.parseInt(totth.toString());
totpr=Theory.getText();
TotMarksPR[i]=Integer.parseInt(totpr.toString());
i++;
}
else
{
button2.setVisibility(View.INVISIBLE);
Theory.setVisibility(View.INVISIBLE);
TheoryMarks.setVisibility(View.INVISIBLE);
Practical.setVisibility(View.INVISIBLE);
PracticalMarks.setVisibility(View.INVISIBLE);
}
}
}
);*/
}
}
and this is the stack trace
> `
03/09 03:33:43: Launching app
$ adb push C:\Users\om\AndroidStudioProjects\MyApplicationin\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.computer.om.myapplicationin
$
adb shell pm install -r "/data/local/tmp/com.computer.om.myapplicationin"
pkg: /data/local/tmp/com.computer.om.myapplicationin
Success
$ adb shell am start -n "com.computer.om.myapplicationin/com.computer.om.myapplicationin.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 2068 on device Nexus_6P_API_17 [emulator-5554]
D/dalvikvm: Not late-enabling CheckJNI (already on)
E/jdwp: Failed writing handshake bytes: Broken pipe (-1 of 14)
D/dalvikvm: Debugger has detached; object registry had 0 entries
E/Trace: error opening trace file: No such file or directory (2)
I/dalvikvm: Could not find method android.app.Application.registerOnProvideAssistDataListener, referenced from method com.android.tools.fd.runtime.BootstrapApplication.registerOnProvideAssistDataListener
W/dalvikvm: VFY: unable to resolve virtual method 232: Landroid/app/Application;.registerOnProvideAssistDataListener (Landroid/app/Application$OnProvideAssistDataListener;)V
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.app.Application.unregisterOnProvideAssistDataListener, referenced from method com.android.tools.fd.runtime.BootstrapApplication.unregisterOnProvideAssistDataListener
W/dalvikvm: VFY: unable to resolve virtual method 235: Landroid/app/Application;.unregisterOnProvideAssistDataListener (Landroid/app/Application$OnProvideAssistDataListener;)V
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/InstantRun: Instant Run Runtime started. Android package is com.computer.om.myapplicationin, real application class is null.
E/InstantRun: Could not find slices in APK; aborting.
W/InstantRun: No instant run dex files added to classpath
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
W/dalvikvm: VFY: unable to resolve check-cast 1924 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x025e
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
W/dalvikvm: VFY: unable to resolve const-class 1924 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
D/dalvikvm: VFY: replacing opcode 0x1c at 0x0060
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa649e908)
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.computer.om.myapplicationin/com.computer.om.myapplicationin.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:151)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.computer.om.myapplicationin.MainActivity.<init>(MainActivity.java:23)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Application terminated.
Outside onCreate you can declare it as
TextView Theory;
and inside onCreate
Theory = (TextView) findViewById(R.id.Theory);
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK