0
나는 안드로이드 프로그래밍에 익숙하지 않다. 현재이 앱을 실행할 때 멈추었다. 다음 여기 Android 스튜디오 오류 : 불행히도 "App"이 (가) 중지되었습니다. 어떻게 해결할 수 있을까요?
12-29 00:35:09.510 3582-3582/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.smartrix.learning4, PID: 3582 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.smartrix.learning4/com.smartrix.learning4.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference 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.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:68) at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:145) at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28) at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41) at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:186) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:170) at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:502) at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:174) at com.smartrix.learning4.MainActivity.<init>(MainActivity.java:16) 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)
내가의 이유 "앱의 작동이 중지"찾을 수있는 방법 내 Main_Activity.java ::
package com.smartrix.learning4;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.support.v4.view.GestureDetectorCompat;
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener{
private GestureDetectorCompat GD;
private TextView UserText = (TextView)findViewById(R.id.Nametext);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Reference the XML code button with JAVA code button
Button button = (Button)findViewById(R.id.Center);
Button button2 = (Button)findViewById(R.id.Right);
Button button3 = (Button)findViewById(R.id.Left);
Button button4 = (Button)findViewById(R.id.Bottom);
Button button5 = (Button)findViewById(R.id.Top);
this.GD = new GestureDetectorCompat(this,this);
GD.setOnDoubleTapListener(this);
//adding listener event
button.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
UserText.setText("CENTER");
}
}
);
button.setOnLongClickListener(
new Button.OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
UserText.setText("It's a Long Click");
return false;
}
}
);
button2.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v) {
UserText.setText("RIGHT");
}
}
);
button3.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v) {
UserText.setText("LEFT");
}
}
);
button4.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v) {
UserText.setText("BOTTOM");
}
}
);
button5.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v) {
UserText.setText("TOP");
}
}
);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
UserText.setText("onSingleTapConfirmed");
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
UserText.setText("onDoubleTap");
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
UserText.setText("onDoubleTapEvent");
return true;
}
@Override
public boolean onDown(MotionEvent e) {
UserText.setText("onDown");
return true;
}
@Override
public void onShowPress(MotionEvent e) {
UserText.setText("onShowPress");
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
UserText.setText("onSingleTapUp");
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
UserText.setText("onScroll");
return true;
}
@Override
public void onLongPress(MotionEvent e) {
UserText.setText("onLongPress");
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
UserText.setText("onFling");
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
this.GD.onTouchEvent(event);
return super.onTouchEvent(event);
}
}
내 로그 캣 ::입니다 ? main_activity 코드에 문제가 있습니까? 어떻게해야합니까? 해결하려면? 도와주세요 ......
AndroidManifest.xml 파일에 MainActivity를 넣었습니까 ?? –
예 @Surace –
예, activity_main.xml이로드되기 전에 UserText에 값을 할당합니다. 이것이 문제입니다. –