我在论坛上找到了很多关于eclipse安卓没有找到的主题的话题,但我花了4个小时来修复它,我仍处于死点。我的sdk没有任何问题,因为我有其他两个项目使用相同的方法Intent to new Activities和正常工作。
public class MainActivity extends Activity {
private Button timer;
protected void onCreate(Bundle contex) {
super.onCreate(contex);
setContentView(R.layout.activity_main);
timer = (Button) findViewById(R.layout.activity_timer);
timer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,Timer.class);
}
});
}
}
MainActivity XML:
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_toLeftOf="@+id/imageButton2"
android:layout_weight="1"
android:background="@drawable/timer_on_click"
android:gravity="left"
android:paddingLeft="3dip"
android:scaleType="center"
android:onClick="activity_timer" />
新活动的XML“activity_timer.xml”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/analogClock1"
android:layout_width="202dp"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
import android.app.Activity;
import android.os.Bundle;
public class Timer extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timer);
}
}
字符串res / values / strings.xml
<string name="activity_timer">activity_timer</string>
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.panic_button"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.panic_button.MainActivity"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.panic_button.Timer"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我尝试了所有内容并且我阅读了很多类似的主题但我仍然没有找到任何解决方案......我有类似的项目,并且它们正常工作,所以sdk很好,Android Manifest一样,我不知道出了什么问题...我会感激任何帮助!