嗨,函数 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");
如果有人可以帮助我尝试很多没有用的东西会很好:)