2017-05-01 9 views
1

저는 학교용 앱에서 일하고 있습니다. 안드로이드와 자바를 배우기 시작했습니다. 나는 버튼을 만들고 새로운 활동을 열기 위해 그것들을 연결했지만, ContactActivity는 android.app.Activity에 계승 될 수 없다는 오류를 얻는다. 여기 내 코드 도움이 필요합니다.연락처 활동을 android.app.Activity로 캐스트 할 수 없습니다.

오류 메시지

info.academypk.parentsportal/info.academypk.parentsportal.SplashScreen}) 
05-01 04:32:25.894 9341-9380/info.academypk.parentsportal W/EGL_emulation: eglSurfaceAttrib not implemented 
05-01 04:32:25.894 9341-9380/info.academypk.parentsportal W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf3f98dc0, error=EGL_SUCCESS 
05-01 04:32:26.369 1333-1359/system_process I/ActivityManager: Displayed info.academypk.parentsportal/.MainActivity: +731ms 
05-01 04:32:29.375 1333-1349/system_process I/ActivityManager: START u0 {cmp=info.academypk.parentsportal/.ContactActivity} from uid 10064 on display 0 
05-01 04:32:29.378 1333-1349/system_process V/WindowManager: addAppToken: AppWindowToken{2e14b321 token=Token{bea9d88 ActivityRecord{15eba52b u0 info.academypk.parentsportal/.ContactActivity t25}}} to stack=1 task=25 at 1 
05-01 04:32:29.378 1333-1393/system_process W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client 
05-01 04:32:29.386 9341-9341/info.academypk.parentsportal D/AndroidRuntime: Shutting down VM 
05-01 04:32:29.386 9341-9341/info.academypk.parentsportal E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: info.academypk.parentsportal, PID: 9341 
                      java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{info.academypk.parentsportal/info.academypk.parentsportal.ContactActivity}: java.lang.ClassCastException: info.academypk.parentsportal.ContactActivity cannot be cast to android.app.Activity 
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236) 
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                       at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:135) 
                       at android.app.ActivityThread.main(ActivityThread.java:5254) 
                       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.ClassCastException: info.academypk.parentsportal.ContactActivity cannot be cast to android.app.Activity 
                       at android.app.Instrumentation.newActivity(Instrumentation.java:1066) 
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226) 
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  
                       at android.app.ActivityThread.access$800(ActivityThread.java:151)  
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  
                       at android.os.Handler.dispatchMessage(Handler.java:102)  
                       at android.os.Looper.loop(Looper.java:135)  
                       at android.app.ActivityThread.main(ActivityThread.java:5254)  
                       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)  
05-01 04:32:29.387 1333-2045/system_process W/ActivityManager: Force finishing activity 1 info.academypk.parentsportal/.ContactActivity 
05-01 04:32:29.388 1333-2045/system_process W/ActivityManager: Force finishing activity 2 info.academypk.parentsportal/.MainActivity 
05-01 04:32:29.488 1333-2680/system_process I/OpenGLRenderer: Initialized EGL, version 1.4 
05-01 04:32:29.551 1333-2680/system_process W/EGL_emulation: eglSurfaceAttrib not implemented 
05-01 04:32:29.551 1333-2680/system_process W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe14e8100, error=EGL_SUCCESS 
05-01 04:32:30.104 1333-1354/system_process I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread. 
05-01 04:32:30.143 1333-1354/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{15eba52b u0 info.academypk.parentsportal/.ContactActivity t25 f} 
05-01 04:32:30.458 1588-2048/com.android.launcher3 W/EGL_emulation: eglSurfaceAttrib not implemented 
05-01 04:32:30.458 1588-2048/com.android.launcher3 W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe25cd720, error=EGL_SUCCESS 
05-01 04:32:31.234 1588-2048/com.android.launcher3 W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer... 
05-01 04:32:31.356 1427-1427/com.android.systemui W/ResourceType: No package identifier when getting value for resource number 0x00000000 
05-01 04:32:31.356 1427-1427/com.android.systemui W/PackageManager: Failure retrieving resources for info.academypk.parentsportal: Resource ID #0x0 
05-01 04:32:31.895 1333-1393/system_process W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client 
05-01 04:32:31.925 9341-9341/info.academypk.parentsportal I/Process: Sending signal. PID: 9341 SIG: 9 
05-01 04:32:31.943 1333-1378/system_process W/InputDispatcher: channel '28d7efe9 info.academypk.parentsportal/info.academypk.parentsportal.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 
05-01 04:32:31.943 1333-1378/system_process E/InputDispatcher: channel '28d7efe9 info.academypk.parentsportal/info.academypk.parentsportal.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 
05-01 04:32:31.970 1333-1780/system_process I/ActivityManager: Process info.academypk.parentsportal (pid 9341) has died 
05-01 04:32:31.971 1333-1350/system_process I/WindowState: WIN DEATH: Window{28d7efe9 u0 info.academypk.parentsportal/info.academypk.parentsportal.MainActivity} 
05-01 04:32:31.971 1333-1350/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '28d7efe9 info.academypk.parentsportal/info.academypk.parentsportal.MainActivity (server)' 
05-01 04:32:32.017 1333-2680/system_process D/OpenGLRenderer: endAllStagingAnimators on 0xded36680 (RippleDrawable) with handle 0xdec3ae70 
05-01 04:32:32.021 1333-2045/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 9341 uid 10064 

AndroidManifest를 파일 :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="info.academypk.parentsportal"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".SplashScreen"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".MainActivity"> 
     </activity> 
     <activity android:name=".ContactActivity"> 
     </activity> 
     <activity android:name=".DailyDiaryActivity"> 
     </activity> 
     <activity android:name=".EventsActivity"> 
     </activity> 
     <activity android:name=".NoticeActivity"> 
     </activity> 
     <activity android:name=".ResultsActivity"> 
     </activity> 
     <activity android:name=".SyllabusActivity"> 
     </activity> 

    </application> 

</manifest> 

MainActivity 파일 :

import android.app.Activity; 
import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 


public class MainActivity extends Activity { 

    Button b1; 
    Button b2; 
    Button b3; 
    Button b4; 
    Button b5; 
    Button b6; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     b1=(Button)findViewById(R.id.Button1); 
     b1.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(MainActivity.this, ContactActivity.class); 
       startActivity(i); 
      } 
     }); 

     b2=(Button)findViewById(R.id.Button2); 
     b2.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(getApplicationContext(),NoticeActivity.class); 
       startActivity(i); 
      } 
     }); 

     b3=(Button)findViewById(R.id.Button3); 
     b3.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(getApplicationContext(),DailyDiaryActivity.class); 
       startActivity(i); 
      } 
     }); 

     b4=(Button)findViewById(R.id.Button4); 
     b4.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(getApplicationContext(),EventsActivity.class); 
       startActivity(i); 
      } 
     }); 

     b5=(Button)findViewById(R.id.Button5); 
     b5.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(getApplicationContext(),SyllabusActivity.class); 
       startActivity(i); 
      } 
     }); 

     b6=(Button)findViewById(R.id.Button6); 
     b6.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent i = new Intent(getApplicationContext(),ResultsActivity.class); 
       startActivity(i); 
      } 
     }); 

    } 


} 

ContactActivity 파일

import android.app.Activity; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 

/** 
* Created by Haris on 5/1/2017. 
*/ 

public class ContactActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 
} 

답변

0

코드에 실수가 없습니다. 오류는 에뮬레이터에서 발생합니다. Tools > Android > AVD Manager > Edit

이동 가상 장치의 선택을 취소은 'Use Host GPU'

사실, 에뮬레이터가 너무 느립니다, 나는 당신이 응용 프로그램을 실행하는 실제 안드로이드 장치를 사용하는 것이 좋습니다.

+0

감사합니다. 그것은 탁월하게 작동합니다, 나는 geny 모션을 사용하고 있습니다. 이제는 잘 작동합니다. –

+0

당신은 천만에요. 나는 그것을 듣게되어 기쁘다. –