的梅索德初始化空指針異常我剛開始一個新的Android項目,與Android註釋庫。 Android AnnotationAndroid的詮釋 - 對生成的
我有兩個活動:StartScreen誰包含一個按鈕「信息」誰啓動一個seconde活動InfoActivity。兩者都註釋。
第一個工作非常好,但是當我點擊「信息」按鈕,我已經得到了NullPointerException
上生成的類的public static class IntentBuilder_
:「InfoActivity_」
這裏是錯誤跟蹤:
04-16 09:32:29.329: E/AndroidRuntime(561): FATAL EXCEPTION: main
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:3122)
at com.cinapp.dombox.tablet.activity.InfoActivity_$IntentBuilder_.<init>(InfoActivity_.java:63)
at com.cinapp.dombox.tablet.activity.InfoActivity_.intent(InfoActivity_.java:53)
at com.cinapp.dombox.tablet.activity.StartScreen.buttonInformation(StartScreen.java:24)
at com.cinapp.dombox.tablet.activity.StartScreen_$1.onClick(StartScreen_.java:44)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
這裏是InfoActivity
或多或少空:
@EActivity(R.layout.activity_info)
public class InfoActivity extends Activity {
}
這裏是InfoActivity_
:
public final class InfoActivity_
extends InfoActivity
{
@Override
public void onCreate(Bundle savedInstanceState) {
init_(savedInstanceState);
super.onCreate(savedInstanceState);
setContentView(layout.activity_info);
}
private void init_(Bundle savedInstanceState) {
}
private void afterSetContentView_() {
}
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
afterSetContentView_();
}
@Override
public void setContentView(View view, LayoutParams params) {
super.setContentView(view, params);
afterSetContentView_();
}
@Override
public void setContentView(View view) {
super.setContentView(view);
afterSetContentView_();
}
public static InfoActivity_.IntentBuilder_ intent(Context context) {
return new InfoActivity_.IntentBuilder_(context);
}
public static class IntentBuilder_ {
private Context context_;
private final Intent intent_;
public IntentBuilder_(Context context) {
context_ = context;
intent_ = new Intent(context, InfoActivity_.class);
}
public Intent get() {
return intent_;
}
public InfoActivity_.IntentBuilder_ flags(int flags) {
intent_.setFlags(flags);
return this;
}
public void start() {
context_.startActivity(intent_);
}
public void startForResult(int requestCode) {
if (context_ instanceof Activity) {
((Activity) context_).startActivityForResult(intent_, requestCode);
} else {
context_.startActivity(intent_);
}
}
}
}
最後這裏是`的Android Manifest``
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exemple.application"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activity.StartScreen_"
android:label="@string/title_activity_start_screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.InfoActivity_"
android:label="@string/title_activity_info" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.exemple.application.activity.StartScreen_" />
</activity>
</application>
</manifest>
它假設是很容易的,但我想錯過的東西
一點題外話,但如果沒有這個'_'風格的名字從何而來?我看到越來越多的人使用這種令人迷惑的名字風格... – WarrenFaith
'_'在最後的類名,用來指代生成的類。它是Android Annotation庫使用的一個約定,請參閱:http://androidannotations.org/ –
啊,好的,謝謝你... – WarrenFaith