java.lang.RuntimeException: Unable to start activity ComponentInfo
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
%d can't format java.lang.String arguments當我login後,就彈main_activity stopped
main_activity.java......extends TabActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, FirstActivity.class);
spec = tabHost.newTabSpec("Display").setIndicator("Display")
.setContent(intent);
tabHost.addTab(spec);
FirstActivity.javapublic class FirstActivity extends Activity implements OnClickListener
{ SQLiteDatabase db;
String sql;
String dataStr = String.format("%4s %15s %3d\n", "ProductCode", "ProductName", "Quantity_in_shop");
Cursor cursor = null;
RadioButton rbName,rbCode,rbAsc,rbDesc;
String[] columns = {"ProductCode", "ProductName", "Quantity_in_shop"};
Button btnShow;
TextView tvdata;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
rbName = (RadioButton) findViewById(R.id.rbName);
rbCode = (RadioButton) findViewById(R.id.rbCode);
rbAsc = (RadioButton) findViewById(R.id.rbAsc);
rbDesc = (RadioButton) findViewById(R.id.rbDesc);
btnShow = (Button) findViewById(R.id.btnshow);
tvdata = (TextView) findViewById(R.id.tvdata);
btnShow.setOnClickListener(this);
try {
// Create a database if it does not exist
db = SQLiteDatabase.openDatabase("/data/data/com.android/eBidDB", null, SQLiteDatabase.CREATE_IF_NECESSARY); sql = "DROP TABLE IF EXISTS Product;";
db.execSQL(sql); sql = "CREATE TABLE Product (ProductCode char PRIMARY KEY, ProductName char, Quantity_in_shop int);";
db.execSQL(sql); db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod01', 'Orange Juice',200); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod02', 'Milk',250); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod03', 'Apple Juice',150); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod04', 'Ice Tea',100); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod05', 'Mineral Water',300); ");
} catch (SQLiteException e) {
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
public void onClick(View v) {
if (v.equals(btnShow)) {
String sortBy = (rbName.isChecked()) ? "ProductCode " : "ProductName ";
String order = (rbAsc.isChecked()) ? "ASC" : "DESC"; try {
db = SQLiteDatabase.openDatabase("/data/data/com.android/eBidDB", null, SQLiteDatabase.OPEN_READONLY);
cursor = db.query("Product", columns, null, null, null, null, sortBy + order);
dataStr = "";;
while (cursor.moveToNext()) {
String PCode = cursor.getString(cursor.getColumnIndex("ProductCode"));
String PName = cursor.getString(cursor.getColumnIndex("ProductName"));
int PQ = cursor.getInt(cursor.getColumnIndex("Quantity_in_shop"));
dataStr += String.format("%4s %15s %3d\n", PCode, PName, PQ);
}
tvdata.setText(dataStr);
db.close();
cursor.close();
} catch (Exception e) {
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.android.login"
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=".FirstActivity">
</activity>
<activity android:name=".SecondActivity">
</activity>
<activity android:name=".ThirdActivity">
</activity>
<activity android:name=".FourthActivity">
</activity>
<activity android:name=".Android_assignmentActivity">
</activity>
</application>
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
%d can't format java.lang.String arguments當我login後,就彈main_activity stopped
main_activity.java......extends TabActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, FirstActivity.class);
spec = tabHost.newTabSpec("Display").setIndicator("Display")
.setContent(intent);
tabHost.addTab(spec);
FirstActivity.javapublic class FirstActivity extends Activity implements OnClickListener
{ SQLiteDatabase db;
String sql;
String dataStr = String.format("%4s %15s %3d\n", "ProductCode", "ProductName", "Quantity_in_shop");
Cursor cursor = null;
RadioButton rbName,rbCode,rbAsc,rbDesc;
String[] columns = {"ProductCode", "ProductName", "Quantity_in_shop"};
Button btnShow;
TextView tvdata;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
rbName = (RadioButton) findViewById(R.id.rbName);
rbCode = (RadioButton) findViewById(R.id.rbCode);
rbAsc = (RadioButton) findViewById(R.id.rbAsc);
rbDesc = (RadioButton) findViewById(R.id.rbDesc);
btnShow = (Button) findViewById(R.id.btnshow);
tvdata = (TextView) findViewById(R.id.tvdata);
btnShow.setOnClickListener(this);
try {
// Create a database if it does not exist
db = SQLiteDatabase.openDatabase("/data/data/com.android/eBidDB", null, SQLiteDatabase.CREATE_IF_NECESSARY); sql = "DROP TABLE IF EXISTS Product;";
db.execSQL(sql); sql = "CREATE TABLE Product (ProductCode char PRIMARY KEY, ProductName char, Quantity_in_shop int);";
db.execSQL(sql); db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod01', 'Orange Juice',200); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod02', 'Milk',250); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod03', 'Apple Juice',150); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod04', 'Ice Tea',100); ");
db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"
+ "('prod05', 'Mineral Water',300); ");
} catch (SQLiteException e) {
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
public void onClick(View v) {
if (v.equals(btnShow)) {
String sortBy = (rbName.isChecked()) ? "ProductCode " : "ProductName ";
String order = (rbAsc.isChecked()) ? "ASC" : "DESC"; try {
db = SQLiteDatabase.openDatabase("/data/data/com.android/eBidDB", null, SQLiteDatabase.OPEN_READONLY);
cursor = db.query("Product", columns, null, null, null, null, sortBy + order);
dataStr = "";;
while (cursor.moveToNext()) {
String PCode = cursor.getString(cursor.getColumnIndex("ProductCode"));
String PName = cursor.getString(cursor.getColumnIndex("ProductName"));
int PQ = cursor.getInt(cursor.getColumnIndex("Quantity_in_shop"));
dataStr += String.format("%4s %15s %3d\n", PCode, PName, PQ);
}
tvdata.setText(dataStr);
db.close();
cursor.close();
} catch (Exception e) {
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.android.login"
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=".FirstActivity">
</activity>
<activity android:name=".SecondActivity">
</activity>
<activity android:name=".ThirdActivity">
</activity>
<activity android:name=".FourthActivity">
</activity>
<activity android:name=".Android_assignmentActivity">
</activity>
</application>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货