Sunday, January 10, 2016

Simulator prompt Unfortunately, Activity has stopped.




            


Just beginning to learn Android development, facing a simple example of a book to write again, the results of running to use the simulator, always prompt Unfortunately, Activity has stopped., Less code, I hope to know to be able to help solve what, grateful .
First code MyView.java
 package picksomething.activity; 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class MyView extends View {
Paint paint;
public MyView (Context context) {
super (context);
paint.setColor (Color.WHITE);
paint.setTextSize (20);
paint.setAntiAlias (true);
}
protected void onDraw (Canvas canvas) {
super.onDraw (canvas);
canvas.drawColor (Color.GRAY);
canvas.drawRect (10, 10, 110, 110, paint);
canvas.drawText ("This interface is customized View", 60, 170, paint);
}

}

The second paragraph of the code ActivityDemo.java
 package picksomething.activity; 


import android.os.Bundle;
import android.app.Activity;

public class ActivityDemo extends Activity {

MyView myView = new MyView (this);
Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
this.setContentView (myView);
}

}

These two java files, because there is no design to layout files, they do not stick layout file it, the project name is the Activity, simulator time is always running to prompt Unfortunately, Activity has stopped.
Reply:
The above information LogCat stickers out

Reply:
& Lt; activity android: name = ". VirtualSkiInstructor" & gt; & lt; / activity & gt;
Reply:
quote 1 floor Ada168855 reply:
The above information LogCat stickers out

Sorry, something these days, I'll just stick.
Reply:
quote the second floor cuit reply:
& lt; activity android: name = ". VirtualSkiInstructor" & gt; & lt; / activity & gt;

Thank you give pointers, plus where to ask, is added to the file you AndroidManifest.xml
Reply:
AndroidManifest.xml is configured to increase activity
Reply:
quote landlord psp0215 reply:
just beginning to learn Android development, facing a simple example of a book to write again, the results of running that time simulator, Always prompt Unfortunately, Activity has stopped., less code, I hope to know to be able to help solve some, be grateful.
First code MyView.java


Java code
?



1234567891011121314151617181920212223

package pickso ......



lz is not no statement ActivityDemo
manifest file in AndroidManifest.xml
Carefully check the operation flow on the lower book mentioned
Reply:
The amount, the above methods are tried, or why not. I posted about logcat inside to error, paste what AndroidManifest.xml file, you help to see.
This is the wrong message.
 
03-25 13: 15: 26.109: E / Trace (937): error opening trace file: No such file or directory (2)
03-25 13: 15: 26.339: D / AndroidRuntime (937): Shutting down VM
03-25 13: 15: 26.399: W / dalvikvm (937): threadid = 1: thread exiting with uncaught exception (group = 0x40a71930)
03-25 13: 15: 26.459: E / AndroidRuntime (937): FATAL EXCEPTION: main
03-25 13: 15: 26.459: E / AndroidRuntime (937): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {picksomething.activity / picksomething.activity.ActivityDemo}: java.lang.NullPointerException
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2106)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2230)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.ActivityThread.access $ 600 (ActivityThread.java:141)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1234)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.os.Handler.dispatchMessage (Handler.java:99)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.os.Looper.loop (Looper.java:137)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.ActivityThread.main (ActivityThread.java:5041)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at java.lang.reflect.Method.invokeNative (Native Method)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at java.lang.reflect.Method.invoke (Method.java:511)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:793)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:560)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at dalvik.system.NativeStart.main (Native Method)
03-25 13: 15: 26.459: E / AndroidRuntime (937): Caused by: java.lang.NullPointerException
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.content.ContextWrapper.getResources (ContextWrapper.java:89)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.view.ContextThemeWrapper.getResources (ContextThemeWrapper.java:78)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.view.View & lt; init & gt; (View.java:3226)
.03-25 13: 15: 26.459: E / AndroidRuntime (937): at picksomething.activity.MyView & lt; init & gt; (MyView.java:11)
.03-25 13: 15: 26.459: E / AndroidRuntime (937): at picksomething.activity.ActivityDemo & lt; init & gt; (ActivityDemo.java:9)
.03-25 13: 15: 26.459: E / AndroidRuntime (937): at java.lang.Class.newInstanceImpl (Native Method)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at java.lang.Class.newInstance (Class.java:1319)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.Instrumentation.newActivity (Instrumentation.java:1054)
03-25 13: 15: 26.459: E / AndroidRuntime (937): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2097)
03-25 13: 15: 26.459: E / AndroidRuntime (937): ... 11 more
03-25 13: 15: 30.619: I / Process (937): Sending signal PID:. 937 SIG: 9


This is AndroidManifest.xml file.
 
& Lt;? Xml version = "1.0" encoding = "utf-8" & gt;?
& Lt; manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "picksomething.activity"
android: versionCode = "1"
android: versionName = "1.0" & gt;

& Lt; uses-sdk
android: minSdkVersion = "8"
android: targetSdkVersion = "17" / & gt;

& Lt; application
android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ style / AppTheme" & gt;
& Lt; activity
android: name = "picksomething.activity.ActivityDemo"
android: label = "@ string / app_name" & gt;
& Lt; intent-filter & gt;
& Lt; action android: name = "android.intent.action.MAIN" / & gt;

& Lt; category android: name = "android.intent.category.LAUNCHER" / & gt;
& Lt; / intent-filter & gt;
& Lt; / activity & gt;
& Lt; / application & gt;

& Lt; / manifest & gt;

Reply:
quote 7th floor psp0215 reply:
the amount of the above methods are tried, or why not. I posted about logcat inside to error, paste what AndroidManifest.xml file, you help to see.
This is the wrong message.


Plain Text code
?



123456789101112131415161718192021222324252627282930

03-25 13: 15: 26.109: E / Trace (937) ......


The list of documents & lt; activity android: name = "picksomething.activity.ActivityDemo"

Need to change & lt; activity android: name = "ActivityDemo"



        


Reply:
quote 7th floor psp0215 reply:
the amount of the above methods are tried, or why not. I posted about logcat inside to error, paste what AndroidManifest.xml file, you help to see.
This is the wrong message.


Plain Text code
?



123456789101112131415161718192021222324252627282930

03-25 13: 15: 26.109: E / Trace (937) ......


And the MyView (Context context) in the super (context); removal
Reply:
quote 8th floor ConnectionUtils reply:
a reference to the 7th floor psp0215 reply: the amount, the above methods are tried, or why not. I posted about logcat inside to error, paste what AndroidManifest.xml file, you help to see.
This is the wrong message.


Plain Text code
?



123456789101112131415161718192021222324252627282930

......

Amount, or not.
Reply:
quote 9th floor ConnectionUtils reply:
a reference to the 7th floor psp0215 reply: the amount, the above methods are tried, or why not. I posted about logcat inside to error, paste what AndroidManifest.xml file, you help to see.
This is the wrong message.


Plain Text code
?



123456789101112131415161718192021222324252627282930

......

Remove this sentence prompts error
Reply:
You do not have new paint it yet
Reply:
quote 12th floor intuition444 reply:
paint you are not new it still

I tried it, too.
Reply:
quote 13th floor psp0215 reply:
a reference to the 12th floor intuition444 reply:
You do not have new paint it also
I tried it, too.

The super (context); put the last line of the method and the paint initialization about ~
Reply:
The

MyView myView = new MyView (this);
Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
this.setContentView (myView);
}
Read:

Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
MyView myView = new MyView (this);
this.setContentView (myView);
}
Ok, now I do not know why, I just started to learn android!
Reply:
Analysis of what know the source due to the: onCreate () function before the constructor call activity objects have run, and this time the object has not been created, so myView point to null, is not referenced, so references to him before initialization, also It is again this.setContentView (myView); before!
Reply:
quote 16th floor flyking247 reply:
analysis of what know the source due to the: onCreate () function before calling the object constructor activity run, this time Object has not been created, so myView point to null, is not referenced, so references to him before initialization, which is then this.setContentView (myView); before!


Thank you! ! ! I thought for a long time or did not result, the last against your approach to solve the
Reply:
I am also a beginner, experienced similar problems. Tinkering in AndroidManifest.xml file
Reply:

Reply:
cite
Thank you! ! ! I thought for a long time or did not result, the last against your approach to solve the

What is the specific solution is? I am also a beginner
Reply:
I also encountered a say in AndroidMenifest.xml, but do not know how to change
Reply:
Permissions SEND_SMS
Reply:

Reply:
quote 17th floor crazyman28 reply:
Quote: references to the 16th floor flyking247 reply:

Analysis of what know the source due to the: onCreate () function before the constructor call activity objects have run, and this time the object has not been created, so myView point to null, is not referenced, so references to him before initialization, also It is again this.setContentView (myView); before!


Thank you! ! ! I thought for a long time or did not result, the last against your approach to solve the
pro, I declare again show how still ah
Reply:
quote 24th floor u013743168 reply:
Quote: quote 17th floor crazyman28 reply:

Quote: references to the 16th floor flyking247 reply:

Analysis of what know the source due to the: onCreate () function before the constructor call activity objects have run, and this time the object has not been created, so myView point to null, is not referenced, so references to him before initialization, also It is again this.setContentView (myView); before!


Thank you! ! ! I thought for a long time or did not result, the last against your approach to solve the
pro, I declare again show how still ah


I am a novice, also encountered, it has been resolved, to those who need reference
Paint paint = new Paint ();
Thank http://www.th7.cn/Program/Android/201407/246852.shtml

No comments:

Post a Comment