喜功能startActivity拋出一個空指針異常 這是我的課:安卓startActivity空指針異常
public class DetailActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
}
public void showHtml(String prod){
Intent myIntent = new Intent(getBaseContext(), DetailActivity.class);
startActivity(myIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.activity_main, menu);
return false;
}
}
,這是我的清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<application android:theme="@android:style/Theme.NoTitleBar" android:allowBackup="false">
<activity
android:name="com.example.xxxx.MainActivity"
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.example.xxxx.fragments.frag1.BarcodeInsertActivity" />
<activity android:name="com.example.xxxx.fragments.frag2.ShopBasketActivity" />
<activity android:name="com.example.xxxx.fragments.frag3.CheckoutActivity" />
<activity android:name="com.example.xxxx.fragments.frag4.DetailActivity" />
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="ZXing"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
這是我嘗試執行功能
DetailActivity gg= new DetailActivity();
gg.showHtml("some html code <div class='someclass'>asdas</div> and other html tags");
會很好,如果有人可以幫我試一試很多事情沒有工作:)
添加您的堆棧跟蹤 – BobTheBuilder 2013-03-07 09:17:20
不要創建活動DetailActivity GG =新DetailActivity對象(); – Pragnani 2013-03-07 09:19:07
從哪裏做這個... DetailActivity gg = new DetailActivity(); – 2013-03-07 09:19:10