这里是代码,第29行对应的bextras按钮配置,它似乎是正确的。 第29行 - extras.setTypeface(font3);当我删除它并启动应用程序时,它会转到extras.setOnClickListener并在那里显示错误,当我删除整个额外按钮及其道具(包括setOnClickListener)时,该应用程序正常工作。应用程序失败,logcat说行29似乎没问题
怎么了?
public class TheBeginning extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_the_beginning);
Button gogym = (Button) findViewById(R.id.bgym);
Typeface font = Typeface.createFromAsset(getAssets(), "Sanvito.ttf");
gogym.setTypeface(font);
Button gofav = (Button) findViewById(R.id.bfav);
Typeface font1 = Typeface.createFromAsset(getAssets(), "Sanvito.ttf");
gofav.setTypeface(font1);
Button goindex = (Button) findViewById(R.id.bindex);
Typeface font2 = Typeface.createFromAsset(getAssets(), "Sanvito.ttf");
goindex.setTypeface(font2);
Button extras = (Button) findViewById(R.id.bextra1);
Typeface font3 = Typeface.createFromAsset(getAssets(), "Sanvito.ttf");
**extras.setTypeface(font3);** //Line 29
TextView minit = (TextView) findViewById(R.id.minititle);
Typeface font4 = Typeface.createFromAsset(getAssets(), "Alba.TTF");
minit.setTypeface(font4);
gogym.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent gogymint = new Intent("com.irespekt.gymbook.GOTOgym");
startActivity(gogymint);
}
});
gofav.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent gofavint = new Intent("com.irespekt.gymbook.GOTOFAV");
startActivity(gofavint);
}
});
goindex.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent goindexint = new Intent(
"com.irespekt.gymbook.INDEXPAGEACTIVITY");
startActivity(goindexint);
}
});
extras.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent extrasint = new Intent(
"com.irespekt.gymbook.PICTUREVIEWFLIP");
startActivity(extrasint);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.the_beginning, menu);
return true;
}
}
编辑
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.com.irespekt.gymbook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.irespekt.gymbook.TheBeginning"
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
android:name="com.irespekt.gymbook.GoToGym"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.irespekt.gymbook.GOTOGYM" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.irespekt.gymbook.GoToFav"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.irespekt.gymbook.GOTOFAV" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.irespekt.gymbook.IndexPageActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.irespekt.gymbook.INDEXPAGEACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.irespekt.gymbook.WebViewActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.irespekt.gymbook.WEBVIEWACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.irespekt.gymbook.PictureViewFlip"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.irespekt.gymbook.PICTUREVIEWFLIP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
布局XML
<LinearLayout
android:id="@+id/LinearLayout04"
android:layout_width="fill_parent"
android:layout_height="186dp"
android:layout_weight="16.78"
android:orientation="vertical" >
<Button
android:id="@+id/bgym"
style="@style/btnStylePaprika"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15.0dip"
android:text="Go To Gym"
android:textSize="20.0sp" />
<Button
android:id="@+id/bfav"
style="@style/btnStylePaprika"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5.0dip"
android:text="Favorites"
android:textSize="20.0sp" />
<Button
android:id="@+id/bindex"
style="@style/btnStylePaprika"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5.0dip"
android:text="Index"
android:textSize="20.0sp" />
<Button
android:id="@+id/bextra1"
style="@style/btnStylePaprika"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5.0dip"
android:text="Extras"
android:textSize="20.0sp" />
</LinearLayout>
logcat的
11-28 12:35:42.598: D/dalvikvm(875): GC_FOR_ALLOC freed 69K, 6% free 2589K/2732K, paused 243ms, total 257ms
11-28 12:35:42.658: I/dalvikvm-heap(875): Grow heap (frag case) to 4.638MB for 2139636-byte allocation
11-28 12:35:42.761: D/dalvikvm(875): GC_FOR_ALLOC freed 2K, 4% free 4676K/4824K, paused 106ms, total 106ms
11-28 12:35:44.048: D/AndroidRuntime(875): Shutting down VM
11-28 12:35:44.048: W/dalvikvm(875): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
11-28 12:35:44.148: E/AndroidRuntime(875): FATAL EXCEPTION: main
11-28 12:35:44.148: E/AndroidRuntime(875): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.irespekt.gymbook/com.irespekt.gymbook.TheBeginning}: java.lang.NullPointerException
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.os.Looper.loop(Looper.java:137)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-28 12:35:44.148: E/AndroidRuntime(875): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 12:35:44.148: E/AndroidRuntime(875): at java.lang.reflect.Method.invoke(Method.java:525)
11-28 12:35:44.148: E/AndroidRuntime(875): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-28 12:35:44.148: E/AndroidRuntime(875): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-28 12:35:44.148: E/AndroidRuntime(875): at dalvik.system.NativeStart.main(Native Method)
11-28 12:35:44.148: E/AndroidRuntime(875): Caused by: java.lang.NullPointerException
11-28 12:35:44.148: E/AndroidRuntime(875): at com.irespekt.gymbook.TheBeginning.onCreate(TheBeginning.java:29)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.Activity.performCreate(Activity.java:5133)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-28 12:35:44.148: E/AndroidRuntime(875): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-28 12:35:44.148: E/AndroidRuntime(875): ... 11 more
11-28 12:36:09.321: I/Process(875): Sending signal. PID: 875 SIG: 9
您可以提供完整的LogCat以及定义了bextra1的布局xml吗? – Grambot
请检查我的编辑 –
@TheCapn请检查我的编辑,它包含您所需要的一切,你是否能够找到任何东西? –