0

我试图从我的主要活动中调用一个活动,但它正在崩溃,我无法弄清楚为什么。

我使用如下按钮从我的主要活动中调用活动

btnStart.setOnClickListener(new View.OnClickListener() {

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

然后使用如下代码打开一个活动,它应该只显示布局shapesscreen.xml(其中没有错误)

public class ShapeScreen extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.shapescreen);
   }
}

第二个活动在我的清单中定义

<activity
    android:name=".MainActivity"
    android:label="Cubic Measurement" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".ShapeScreen"
    android:label="Cubic Measurement" >
    <intent-filter>
        <action android:name="kurt.steveboss.shapescreen" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

但是,当我单击此按钮时,应用程序崩溃,并且我的 LogCat 中出现以下错误

 01-02 15:03:37.550: I/InputReader(2100): Touch event's action is 0x1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=]
 01-02 15:03:37.550: I/InputDispatcher(2100): Delivering touch to current input target: action: 0x1
 01-02 15:03:37.550: I/InputDispatcher(2100): Delivering touch to current input target: action: 0x1
 01-02 15:03:37.550: I/InputDispatcher(2100): Delivering touch to current input target: action: 0x1
 01-02 15:03:37.555: I/ActivityManager(2100): START {intent.toShortString} from pid 8045
 01-02 15:03:37.555: I/power(2100): *** acquire_dvfs_lock : lockType : 1  freq : 1000000 
 01-02 15:03:37.555: D/PowerManagerService(2100): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1000000  uid : 1000  pid : 2100  tag : ActivityManager
 01-02 15:03:37.555: W/ActivityManager(2100): mDVFSLock.acquire()
 01-02 15:03:37.570: D/ActivityManager(2100): Trying to launch applicationName
 01-02 15:03:37.580: D/KeyguardViewMediator(2100): setHidden false
 01-02 15:03:37.650: D/dalvikvm(8045): GC_FOR_ALLOC freed 22K, 2% free 18560K/18887K, paused 10ms
 01-02 15:03:37.655: I/dalvikvm-heap(8045): Grow heap (frag case) to 21.095MB for 2903056-byte allocation
 01-02 15:03:37.680: D/dalvikvm(8045): GC_CONCURRENT freed 2K, 2% free 21393K/21767K, paused 1ms+1ms
 01-02 15:03:37.765: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 21394K/21767K, paused 9ms
 01-02 15:03:37.770: I/dalvikvm-heap(8045): Grow heap (frag case) to 23.864MB for 2903056-byte allocation
 01-02 15:03:37.790: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 24229K/24647K, paused 1ms+2ms
 01-02 15:03:37.875: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 24231K/24647K, paused 10ms
 01-02 15:03:37.880: I/dalvikvm-heap(8045): Grow heap (frag case) to 26.634MB for 2903056-byte allocation
 01-02 15:03:37.900: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 27066K/27527K, paused 2ms+2ms
 01-02 15:03:37.985: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 27067K/27527K, paused 9ms
 01-02 15:03:37.995: I/dalvikvm-heap(8045): Grow heap (frag case) to 29.404MB for 2903056-byte allocation
 01-02 15:03:38.015: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 29902K/30407K, paused 1ms+1ms
 01-02 15:03:38.095: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 29904K/30407K, paused 9ms
 01-02 15:03:38.105: I/dalvikvm-heap(8045): Grow heap (frag case) to 32.174MB for 2903056-byte allocation
 01-02 15:03:38.125: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 32739K/33287K, paused 1ms+1ms
 01-02 15:03:38.210: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 32741K/33287K, paused 10ms
 01-02 15:03:38.220: I/dalvikvm-heap(8045): Grow heap (frag case) to 34.944MB for 2903056-byte allocation
 01-02 15:03:38.235: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 35576K/36167K, paused 2ms+2ms
 01-02 15:03:38.315: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 35578K/36167K, paused 9ms
 01-02 15:03:38.325: I/dalvikvm-heap(8045): Grow heap (frag case) to 37.714MB for 2903056-byte allocation
 01-02 15:03:38.340: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 38413K/39047K, paused 2ms+2ms
 01-02 15:03:38.415: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 38414K/39047K, paused 10ms
 01-02 15:03:38.430: I/dalvikvm-heap(8045): Grow heap (frag case) to 40.485MB for 2903056-byte allocation
 01-02 15:03:38.445: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 41249K/41927K, paused 2ms+2ms
 01-02 15:03:38.555: I/power(2100): *** release_dvfs_lock : lockType : 1 
 01-02 15:03:38.555: D/PowerManagerService(2100): releaseDVFSLockLocked : all DVFS_MIN_LIMIT are released 
 01-02 15:03:38.555: W/ActivityManager(2100): mDVFSLock.release()
 01-02 15:03:38.975: W/PowerManagerService(2100): Timer 0x7->0x3|0x0
 01-02 15:03:38.975: I/PowerManagerService(2100): Ulight 0x7->0x3|0x0
 01-02 15:03:38.975: D/lights(2100): write_int /sys/class/sec/sec_touchkey/brightness = 2
 01-02 15:03:38.975: D/PowerManagerService(2100): setLightBrightness : mButtonLight : 0
 01-02 15:03:39.725: D/KeyguardViewMediator(2100): handleTimeout
4

3 回答 3

2

您应该使用该.class方法来启动您的 Activity。

btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, ShapeScreen.class);
                startActivity(i);   
            }
        });
于 2013-01-02T02:41:43.070 回答
1

我认为您没有在应用程序中的 AndroidManifest.xml 文件上启动活动。您只需在 AndroidManifestfie 上尝试此代码

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

现在你可以试试这肯定会奏效

于 2013-01-02T04:44:20.560 回答
1

用这个

@Override
            public void onClick(View v) {
                Intent i = new Intent("YOUR_ACTIVITY_CLASS.this,ShapeScreen.class");
                startActivity(i);   
            }

代替

 @Override
        public void onClick(View v) {
            Intent i = new Intent("kurt.steveboss.shapescreen");
            startActivity(i);   
        }
于 2013-01-02T02:43:15.120 回答