我正试图从我的主动作中调用一个活动,但它崩溃了我无法弄清楚原因。
我使用按钮调用我的mainactivity中的活动,如下所示
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, ShapeScreen.class);
startActivity(i);
}
});
然后打开一个带有如下代码的活动,它应该只显示layoutsscreen.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
答案 0 :(得分:2)
您应该使用.class
方法启动您的活动。
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, ShapeScreen.class);
startActivity(i);
}
});
答案 1 :(得分: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);
}
答案 2 :(得分:1)
我认为您没有在应用中的AndroidManifest.xml文件上启动活动。您只需在AndroidManifestfie上试用此代码
<activity
android:name=" .ShapeScreen" >
</activity>
现在你可以试试这肯定会起作用