こんにちは関数startActivityはnullpointer例外をスローしますこれは私のクラスです:
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");
何もうまくいかなかった多くのことを試してみるのを手伝ってくれる人がいたらいいのにと思います:)