Throwing multiple exceptions Java
Throws multiple exceptions Java example source code
public void callFc()
throws IndexOutOfBoundsException, ArithmeticException
{
// my code for example:
String[] sArray = {"aa","bb"};
String str = sArray[5]; // IndexOutOfBoundsException
int n = 5 / 0; // ArithmeticException
}
public void someFC (){
try{
callFc();
}
catch(IndexOutOfBoundsException e){
Log.e("TAG", e.toString());
}
catch(ArithmeticException e2){
Log.e2("TAG",e2.toString());
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
Calendar cal = new GregorianCalendar();
int era = cal.get(Calendar.ERA); // 0 B.C. before Christ, 1 Anno Domini
txtV.setText(txtV.getText() +"
" + era);
int year = cal.get(Calendar.YEAR); // 2011
txtV.setText(txtV.getText() +"
" + year);
int month = cal.get(Calendar.MONTH); // 0 is Januar
txtV.setText(txtV.getText() +"
" + month);
int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31
txtV.setText(txtV.getText() +"
" + day);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ...
txtV.setText(txtV.getText() +"
" + dayOfWeek);
}
}
I tried this Eclipse and work fine:
Eclipse Classic
//www.filehippo.com/download_eclipse_classic_32/
Eclipse Juno
Eclipse Helios
//developer.android.com/tools/sdk/eclipse-adt.html
Eclipse Classic
//www.filehippo.com/download_eclipse_classic_32/
Eclipse Juno
Eclipse Helios
//developer.android.com/tools/sdk/eclipse-adt.html
For and continue statement in Java.
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
for (int i = 0; i < arrayOfString.length; i++){
if(arrayOfString[i].equals("hello"))
continue; // skip to for
System.out.println(arrayOfString[i]);
}
}
}
/*
Hello
people
world!
*/
Change table row background color if user click on row Android example code.
MainActivity.java
main.xml
strings.xml
MainActivity.java
public class MainActivity extends Activity {
Boolean bColorYellow = true;
TextView hTextView;
TableRow hTableRow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hTextView = (TextView)findViewById(R.id.idTextView);
hTableRow = (TableRow)findViewById(R.id.idTableRow1);
} // end onCreate
public void myTableRowClickHandler(View view) {
switch (view.getId()) {
case R.id.idTableRow1:{
if(bColorYellow){
hTableRow.setBackgroundColor(Color.GREEN);
bColorYellow = false;
}
else{
hTableRow.setBackgroundColor(Color.YELLOW);
bColorYellow = true;
}
}
break;
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/tableLayout1">
<TableRow android:id="@+id/idTableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#5655AA"
android:onClick="@string/myTableRowClick"
android:focusable="true">
<TextView
android:id="@+id/idTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</TableRow>
</TableLayout>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World!</string>
<string name="app_name">TableRow</string>
<string name="myTableRowClick">myTableRowClickHandler</string>
</resources>
Try this solutions:
1.) Save xml file
2.) Close tab with xml file
3.) Reopen xml file
1.) Open from menu Window->Android SDK Manager
2.) Select available updates (Tools, SDK etc.)
3.) Install updates
1.) Open from menu Help->Check for Updates
2.) Install available plugins what You need
3.) Restart Eclipse
1.) Save xml file
2.) Close tab with xml file
3.) Reopen xml file
1.) Open from menu Window->Android SDK Manager
2.) Select available updates (Tools, SDK etc.)
3.) Install updates
1.) Open from menu Help->Check for Updates
2.) Install available plugins what You need
3.) Restart Eclipse
Editace: 2013-12-09 10:15:41
Počet článků v kategorii: 396
Url:throwing-multiple-exceptions-java