簡體   English   中英

我的android應用在模擬器中崩潰

[英]My android app crashes in the emulator

我試圖制作一個簡單的應用程序,我想添加一個新的Activity,但是當我在模擬器上運行應用程序時(Eclipse不會給我任何錯誤),它只會崩潰。

這是我的日志:

09-21 05:18:13.066: I/Process(255): Sending signal. PID: 255 SIG: 9
09-21 05:18:13.106: I/ActivityManager(52): Process com.example.proyecto_1 (pid 255) has died.
09-21 05:18:13.172: I/UsageStats(52): Unexpected resume of com.android.launcher while     already resumed in com.example.proyecto_1
09-21 05:18:13.402: E/gralloc(52): [unregister] handle 0x14d478 still locked (state=40000001)
09-21 05:18:13.462: W/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44de1dc8
09-21 05:18:16.193: W/KeyCharacterMap(107): No keyboard for id 0
09-21 05:18:16.203: W/KeyCharacterMap(107): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-21 05:18:18.594: I/ActivityManager(52): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.proyecto_1/.MainActivity }
09-21 05:18:18.673: I/ActivityManager(52): Start proc com.example.proyecto_1 for activity com.example.proyecto_1/.MainActivity: pid=261 uid=10028 gids={}
09-21 05:18:18.913: D/ddm-heap(261): Got feature list request
09-21 05:18:19.083: D/AndroidRuntime(261): Shutting down VM
09-21 05:18:19.123: W/dalvikvm(261): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
09-21 05:18:19.123: E/AndroidRuntime(261): Uncaught handler: thread main exiting due to uncaught exception
09-21 05:18:19.233: E/AndroidRuntime(261): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.proyecto_1/com.example.proyecto_1.MainActivity}: java.lang.ClassNotFoundException: com.example.proyecto_1.MainActivity in loader dalvik.system.PathClassLoader@4001b500
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.os.Looper.loop(Looper.java:123)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.app.ActivityThread.main(ActivityThread.java:4363)
09-21 05:18:19.233: E/AndroidRuntime(261):  at java.lang.reflect.Method.invokeNative(Native Method)
09-21 05:18:19.233: E/AndroidRuntime(261):  at java.lang.reflect.Method.invoke(Method.java:521)
09-21 05:18:19.233: E/AndroidRuntime(261):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-21 05:18:19.233: E/AndroidRuntime(261):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-21 05:18:19.233: E/AndroidRuntime(261):  at dalvik.system.NativeStart.main(Native Method)
09-21 05:18:19.233: E/AndroidRuntime(261): Caused by: java.lang.ClassNotFoundException: com.example.proyecto_1.MainActivity in loader dalvik.system.PathClassLoader@4001b500
09-21 05:18:19.233: E/AndroidRuntime(261):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
09-21 05:18:19.233: E/AndroidRuntime(261):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
09-21 05:18:19.233: E/AndroidRuntime(261):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
09-21 05:18:19.233: E/AndroidRuntime(261):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-21 05:18:19.233: E/AndroidRuntime(261):  at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
09-21 05:18:19.233: E/AndroidRuntime(261):  ... 11 more
09-21 05:18:19.314: I/Process(52): Sending signal. PID: 261 SIG: 3
09-21 05:18:19.314: I/dalvikvm(261): threadid=7: reacting to signal 3
09-21 05:18:19.333: I/dalvikvm(261): Wrote stack trace to '/data/anr/traces.txt'
09-21 05:18:21.073: I/Process(261): Sending signal. PID: 261 SIG: 9
09-21 05:18:21.093: I/ActivityManager(52): Process com.example.proyecto_1 (pid 261) has died.
09-21 05:18:21.114: I/UsageStats(52): Unexpected resume of com.android.launcher while already resumed in com.example.proyecto_1
09-21 05:18:21.263: W/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44dae108

這是我的MainActivity:

package com.example.proyecto_1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

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

    Button button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent test_scrn1 = new Intent(MainActivity.this, TestScrn1.class);
            startActivity(test_scrn1);
        }
    });

    }
}

最后這是我的AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.proyecto_1"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:hasCode="false" android:allowTaskReparenting="false">
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="TestScrn1"></activity>
</application>

我不知道自己在做什么錯,我一直在尋找解決方案,但請幫幫我。

您的錯誤有很多可能性。

  • 首先放置(。)DOT在android中引導您的TestScrn1活動聲明。
  • 確保清單文件中的android:hasCode沒有設置為false。
  • 清理您的項目,然后再次運行。
  • 勾選項目>自動生成。

這是dot(.)的問題。

清單文件中的更改。

<activity android:name="TestScrn1"></activity>

(至)

<activity android:name=".TestScrn1"></activity>

優良作法是給出完全合格的類名稱,例如

<activity android:name="com.example.proyecto_1.TestScrn1"></activity>

你應該為此

<activity android:name=".Your Activity Name"></activity>

and Dont Remove dot(.)

還有更多的可能性

  • 再次保存您的xml文件
  • 清理您的項目
  • 檢查您的班級名稱
  • 它不必要的Put(。),所以不用擔心
  • 還要檢查對此方法進行分類

      @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.yourlayout); } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM