פורסם 2011 באוקטובר 2514 שנים שלום לכולםיש בעיה בקוד הזה (לפי אקליפס ולפי ה-ADK)package android.battun;import android.app.Activity;import android.os.Bundle;import android.widget.Button;import android.widget.EditText;import android.view.View.OnClickListener;import android.widget.Toast;import android.content.Context;import android.view.View;public class AndroidtesttwoActivity extends Activity { EditText helloName; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText helloName; Button button = (Button)findViewById(R.id.go); // Register the onClick listener with the implementation above button.setOnClickListener(mAddListener); } // Create an anonymous implementation of OnClickListener private OnClickListener mAddListener = new OnClickListener() { public void onClick(View v) { long id = 0; // do something when the button is clicked try { helloName = (EditText)findViewById(R.id.go); Context context = getApplicationContext(); CharSequence text = "Hello " + helloName.getText() + "!"; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); } catch (Exception ex) { Context context = getApplicationContext(); CharSequence text = ex.toString() + "ID = " + id; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } };}הבעיה היא בשורה:helloName = (EditText)findViewById(R.id.go);ובשורה:Button button = (Button)findViewById(R.id.go);בשתי השורות הבעיה היא במה שבסוגריים מה לעשות?
פורסם 2011 באוקטובר 2514 שנים 1. האם ערכת את ה XML בהתאם?2. לא נראה לי הגיוני שאת מנסה פעם אחת לתת לכפתור ופעם אחת לתיבת עריכה את אותו ה id תבדוק את עצמך
פורסם 2011 באוקטובר 2714 שנים וכמו ש-trex אמר, אין מצב ש-R.id.go שייך גם לכפתור וגם לתיבת טקסט (אלא אם כן יצרת איזה custom control שאיכשהו ממש את שניהם, אבל גם זה לא אפשרי למיטב ידיעתי).אני מניח שהמתודה findViewById מחזירה לך null ולכן ההמרה נופלת ומתקבלת השגיאה.תשימי פה את הקוד מ-main.xml שנראה מזה בדיוק ה-go הזה...
פורסם 2011 באוקטובר 2714 שנים מחבר אההה וואי איזה דביל אני לא שמתי לב שנתתי לשניהם אותו ID.... ויש לי עוד שאלה איך קוראים למתודה/מחלקה אחרת? אני רוצה שכשהמשתמש ילחץ על הכפתור יפתח לו חלון (layout) אחר. (זה לא כמו תכנות רגיל ב-JAVA ) class.method(); דרך אגב מישהו מכיר מדריך טוב לפיתוח אפליקציות לאנדרואיד? (יודע JAVA מעולה)
פורסם 2011 באוקטובר 2714 שנים Apress Beginning android 3ספר טוב לדעתיולגבי השאלה שלך על מנת לפתוח layout אחר כדאי ליצור ולהריץ activity נפרדתאם אתה לא יודע איך עושים זאת תסתכל בספר עמוד 218
פורסם 2011 באוקטובר 2714 שנים מחבר התכוונתי מדריך אינטרנטי (כבר הזמנתי שני ספרים מאמזון)אני יודע איך ליצור layout ולחבר אותה עם ה-activity מה שאני לא יודע זה איך לקרוא ל-activity
פורסם 2011 באוקטובר 2814 שנים u will need to write the activity in the manifest.xml filelike <activity android:label="selectionMenu" android:name=".SelectionMenu" > </activity>where's name is the class name for the activity (the dot is the package name)label is just what you will see in the titlein the java code you will need to create an intent like thisIntent i = new Intent(this, SelectionMenu.class); "this" is the class u are calling from so u need to call the constructor outside any functionwhen you want to load the activity just callstartActivity(i) and the activity will start
פורסם 2011 באוקטובר 2914 שנים א. תעשה import ל android.content.intentב. תכריז מחוץ לפונקציות (לא ב oncreate) בתוך המחלקה (כדי שthis יפנה למופע המחלקה עצמה)אגב חברים: איזו פונקציה נותנת את הקונטקסט הנוכחי? אם הייתי רוצה ליצור את האינטנט ב oncreate
פורסם 2012 באפריל 2913 שנים לא מצליח ליצור:Intent i = new Intent(AndroidtesttwoActivity.this, SelectionMenu.class);תנסה את התיקון שעשיתי להודעה שלך
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.