开发者

Source not found!

I'm trying to write an application that opens another window when a button is selected here is what I have so far:

public class AndroidAlarm extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

            Button codesBtn = (Button)findViewById(R.id.imagebutton1);
    codesBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View argo) {
            Intent i = new Intent(AndroidAlarm.this, Codes.class);
            startActivity(i);
        }
    });

   }
}

This is what I have in my default class, the activity I'm trying to start is a class called Codes:

public class Codes extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.codes);
    }
}

It will have functionality but right now I'm just trying to open it. Codes.java (above) is connected to a layout called codes.xml.

My manifest file looks like this:

<?xml version="1.0" encoding="utf-8"?&g开发者_高级运维t;
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.affirma.androidalarm"
  android:versionCode="1"
  android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity class =".AndroidAlarm" android:name = ".AndroidAlarm"
                  android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity class = ".Codes" android:name = ".Codes" android:label="Codes">
        </activity>
    </application>
</manifest>

When I run the program, it will start then crash saying it ended abruptly. When I debug, it breaks at this line found in AndroidAlarm.java:

codesBtn.setOnClickListener(new View.OnClickListener() {

It says that the Source is not found. something about "activitythread.preformlauncher..." Anyways I don't know why this is happening any suggestions?


The Error is because it is trying to find the id of "imagebutton1" from R.java files which is in the R.layout.main. so please make sure you have imagebutton1 has been initialized properly and R.java contains the id of the same.


are you sure that your imagebutton1 is in the R.layout.main? i tried your code and it's working fine

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜