Search Results

Search found 4035 results on 162 pages for 'extends'.

Page 83/162 | < Previous Page | 79 80 81 82 83 84 85 86 87 88 89 90  | Next Page >

  • Catch a generic exception in Java?

    - by Alex Baranosky
    We use JUnit 3 at work and there is no ExpectedException annotation. I wanted to add a utility to our code to wrap this: try { someCode(); fail("some error message"); } catch (SomeSpecificExceptionType ex) { } So I tried this: public static class ExpectedExceptionUtility { public static <T extends Exception> void checkForExpectedException(String message, ExpectedExceptionBlock<T> block) { try { block.exceptionThrowingCode(); fail(message); } catch (T ex) { } } } However, Java cannot use generic exception types in a catch block, I think. How can I do something like this, working around the Java limitation? Is there a way to check that the ex variable is of type T?

    Read the article

  • How to implement collection with covariance when delegating to another collection for storage?

    - by memelet
    I'm trying to implement a type of SortedMap with extended semantics. I'm trying to delegate to SortedMap as the storage but can't get around the variance constraints: class IntervalMap[A, +B](implicit val ordering: Ordering[A]) //extends ... { var underlying = SortedMap.empty[A, List[B]] } Here is the error I get. I understand why I get the error (I understand variance). What I don't get is how to implement this type of delegation. And yes, the covariance on B is required. error: covariant type B occurs in contravariant position in type scala.collection.immutable.SortedMap[A,List[B]] of parameter of setter underlying_=

    Read the article

  • How to rotate a figure without moving around the stage(actionscript)

    - by Mister PHP
    package { import flash.display.MovieClip; import flash.events.Event; public class Bullet extends MovieClip { private var mc:MovieClip; public function Bullet() { mc = new MovieClip(); mc.graphics.beginFill(0); mc.graphics.drawRect(120, 120, 40, 40); mc.graphics.endFill(); addChild(mc); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(e:Event):void{ mc.rotation += 10; } } } how can i make the rotation of the circle without moving him around the stage, just staying in the place he was before and just rotate, not moving anywhere is that posible?? if you try this code you'll see that the circle is rotating and moving around the stage, so that i don't want, how can i change this?

    Read the article

  • Explicit constructor still has default values even though a default constructor is not invoked.

    - by Phoenix
    According to my understanding a default constructor initializes the state of the object to default values, so if i provide an explicit no-arg public constructor like this then how are the values of d and e still getting initialized to zero because in this case the default constructor is not invoked. public class B extends A{ private int d; private int e; public B() { System.out.println(d); System.out.println(e); } } EDIT:: The only thing default constructor does is call to super() then how come if i have a explicitly mentioned a constructor here and A has a protected variable say c which is initialized to 17 in its constructor. Should I not be explicitly calling super() to be able to see that change since I'm using my own constructor ? Why is B still getting the value of 17 through inheritance ?

    Read the article

  • Deprecated Preference Activity method

    - by Adnan Nazir
    package com.adi.preferencedemotest; i am working on PreferenceActivity but when i call my preference xml(prefs.xml) with the help of addPreferencesFromResource it says this method is deprecated and "This function is not relevant for a modern fragment-based PreferenceActivity" is there any alternative of this method? how i can handle ? public class PrefsActivity extends PreferenceActivity { @SuppressWarnings("deprecation") <------- @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); <------- } } Note: may be my question rate as duplicated but i didn't find any.

    Read the article

  • Abstract class get parameter from implementing subclass?

    - by soren.qvist
    I'm wondering if there is way to do this without breaking encapsulation, I want the abstract class to rely on parameters defined in the implementing subclass. Like so: public abstract class Parent { private int size; private List<String> someList; public Parent() { size = getSize(); someList = new ArrayList<String>(size); } public abstract int getSize(); } public class Child extends Parent { @Override public int getSize() { return 5; } } Is this ugly? Is there a better way? And perhaps more importantly, is this even a good idea?

    Read the article

  • Subtype polymorphism and arrays

    - by user133466
    Computer[] labComputers = new Computer[10]; with public class Computer { ... void toString(){ // print computer specs } } public class Notebook extends Computer{ ... void toString(){ // print computer specs + laptop color } } each subscripted variable labComputers[i] can reference either a Computer object or a Notebook object because Notebook is a subclass of Computer. For the method call labComputers[i].toString(), polymorphism ensures that the correct toString method is called. I wonder what if we do Notebook[] labComputers = new Notebook[10]; what kind or error would I get if I reference with Computer object and a Notebook object

    Read the article

  • How Can we hide title bar while using action bar?

    - by Arci
    I'm using ActionBarSherlock and I'm trying to hide the title bar of my application but whenever I do that, I get a NullPointerException when accessing the ActionBar How do I remove/hide the title bar? Please note that I'm not referring to the title of the action bar. I'm referring to the title bar above the action bar. I'm running my application on an Android 2.3 device. Below is my code: (My class extends SherlockFragmentActivity.) super.onCreate(savedInstanceState); setTheme(R.style.Theme_Sherlock); this.requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionbar = getSupportActionBar(); actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //I get the NullPointerException here. //... setContentView(R.layout.tab_navigation);

    Read the article

  • FLEX, Actionscript: how can I invoke a CustomEvent ?

    - by Patrick
    hi, I've created a custom MouseEvent in Flex: package { import flash.events.MouseEvent; public class CustomMouseEvent extends MouseEvent { public var tags:Array = new Array(); public function CustomMouseEvent(type:String, tags:Array) { super(type, true); this.tags = tags; } } } Now I would like to understand how to pass the parameter tags from both Actionscript and MXML: From actionscript I'm trying something like this, but it doesn't work: newTag.addEventListener(MouseEvent.MOUSE_UP, dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP,[newTag.name]))); From MXML i'm doing this and it doesn't work as well: <mx:LinkButton click="dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP, bookmarksRepeater.currentItem.tags))" /> thanks

    Read the article

  • How to access constant defined in child class from parent class functions?

    - by kavoir.com
    I saw this example from php.net: <?php class MyClass { const MY_CONST = "yonder"; public function __construct() { $c = get_class( $this ); echo $c::MY_CONST; } } class ChildClass extends MyClass { const MY_CONST = "bar"; } $x = new ChildClass(); // prints 'bar' $y = new MyClass(); // prints 'yonder' ?> But $c::MY_CONST is only recognized in version 5.3.0 or later. The class I'm writing may be distributed a lot. Basically, I have defined a constant in ChildClass and one of the functions in MyClass (father class) needs to use the constant. Any idea?

    Read the article

  • Pagination, next page doesn`t display

    - by user1738013
    if I click page 2 that`s error: Not Found The requested URL /rank/GetAll/30 was not found on this server. My link is: http://localhost/rank/GetAll/30 Model: Rank_Model <?php Class Rank_Model extends CI_Model { public function __construct() { parent::__construct(); } public function record_count() { return $this->db->count_all("ranking"); } public function fifa_rank($limit, $start) { $this->db->limit($limit, $start); $query = $this->db->get("ranking"); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { $data[] = $row; } return $data; } return false; } } ?> Controller: Rank <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class rank extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper("url"); $this->load->helper(array('form', 'url')); $this->load->model('Rank_Model','',TRUE); $this->load->library("pagination"); } function GetAll() { $config = array(); $config["base_url"] = base_url() . "rank/GetAll"; $config["total_rows"] = $this->Rank_Model->record_count(); $config["per_page"] = 30; $config["uri_segment"] = 3; $this->pagination->initialize($config); $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; $data["results"] = $this->Rank_Model->fifa_rank($config["per_page"], $page); $data['errors_login'] = array(); $data["links"] = $this->pagination->create_links(); $this->load->view('left_column/open_fifa_rank',$data); } } View Open: open_fifa_rank <?php $this->load->view('mains/header'); $this->load->view('login/loggin'); $this->load->view('mains/menu'); $this->load->view('left_column/left_column_before'); $this->load->view('left_column/menu_left'); $this->load->view('left_column/left_column'); $this->load->view('center/center_column_before'); $this->load->view('left_column/fifa_rank'); $this->load->view('center/center_column'); $this->load->view('right_column/right_column_before'); $this->load->view('login/zaloguj'); $this->load->view('right_column/right_column'); $this->load->view('mains/footer'); ?> and View: fifa_rank <table> <thead> <tr> <td>Pozycja</td> <td>Kraj</td> <td>Punkty</td> <td>Zmiana</td> </tr> </thead> <?php foreach($results as $data) {?&gt; <tbody> <tr> <td><?php print $data->pozycja;?></td> <td><?php print $data->kraj;?></td> <td><?php print $data->punkty;?></td> <td><?php print $data->zmiana;?></td> </tr> <?php } ?> </tbody> </table> <p><?php echo $links; ?></p> Maybe you know where is my problem? Now I know where is my problem. In first page I have link: http://localhost/index.php/rank/GetAll But on the next: http://localhost/rank/GetAll/30 In secend link, I don`t have index.php. How can I fix it?

    Read the article

  • Weird error: [Semantical Error] line 0, col 75 near 'submit': Error: 'submit' is not defined.

    - by luxury
    My controller like: /** * @Route("/product/submit", name="product_submit") * @Template("GaorenVendorsBundle:Product:index.html.twig") */ public function submitAction() { $em = $this->getDoctrine()->getManager(); $uid = $this->getUser()->getId(); $em->getRepository( 'GaorenVendorsBundle:Product' )->updateStatus( $uid, Product::STATUS_FREE, Product::STATUS_PENDING ); return $this->redirect( $this->generateUrl( 'product' ) ); } and the repo like: class ProductRepository extends EntityRepository { public function updateStatus($uid, $status, $setter) { $st = $this->getEntityManager()->getRepository( 'GaorenVendorsBundle:Product' ) ->createQueryBuilder( 'p' ) ->update( 'GaorenVendorsBundle:Product', 'p' ) ->set( 'p.status', ':setter' ) ->where( 'p.status= :status AND p.user= :user' ) ->setParameters( array( 'user' => $uid, 'status' => $status, 'setter' => $setter ) ) ->getQuery() ->execute() return $st; } when request the "submit" action, it prompts me "[Semantical Error] line 0, col 75 near 'submit': Error: 'submit' is not defined. ". "submit" is nothing to do with DOCTRINE orm query, why it appears in the error? I just can't figure out.Anyone could tell me?

    Read the article

  • visual tool to resolve conflicts merged into a single file

    - by Yehosef
    I did a git merge and ended up with a file like that looks like this: class member extends item{ /********CONSTANTS**********/ const is_flaggable = true; const is_commentable = false; const is_ratable = false; const table = 'member'; <<<<<<< HEAD const table_about = 'mem_about' ; const table_to_about = 'mem_to_about' ; const table_hobbies = 'mem_to_hobby'; ======= const table_friendship = 'friendship'; const table_about = 'mem_about' ; const table_to_about = 'mem_to_about' ; const table_hobbies = 'mem_to_hobby'; const table_friendship_id = 3; >>>>>>> my-copy In this file there are many blocks like this. Is there a visual tool to help me look at this file and pick and choose the changes I want? Most of the diff tools I found are for looking at two files.

    Read the article

  • How to get data from dynamically created EditText views and insert it into an array?

    - by Snwspeckle
    So basically what I need my program to do at this point is that when I click the submit button, I need to loop through each dynamic row of the ListView and grab the value in the EditText view and then insert that into an array which I will do further calculations after. Here is my code right now. package com.hello_world; import java.util.ArrayList; import com.hello_world.ByteInputActivity.MyAdapter.ViewHolder; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnFocusChangeListener; import android.view.View.OnKeyListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; public class ByteInputActivity extends Activity { private ListView myList; private MyAdapter myAdapter; private Integer resQuestions; private Integer indexVal = 0; private View caption; ViewHolder holder; ArrayList<Integer> intArrayList = new ArrayList<Integer>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fieldlist); //Gets number of questions from MainActivity Bundle extras = getIntent().getExtras(); if(extras !=null) { resQuestions = extras.getInt("index"); } myList = (ListView) findViewById(R.id.FieldList); myList.setItemsCanFocus(true); myAdapter = new MyAdapter(); myList.setAdapter(myAdapter); Button submit = (Button) findViewById(R.id.btn_New); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < myList.getCount() ; i++) { View vListSortOrder; vListSortOrder = myList.getChildAt(i); String temp = holder.caption.getText().toString(); Log.e("VALUES", "" +temp); } } }); } public class MyAdapter extends BaseAdapter { private LayoutInflater mInflater; public ArrayList myItems = new ArrayList(); public MyAdapter() { mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < resQuestions; i++) { ListItem listItem = new ListItem(); listItem.caption = "Index " + i; listItem.indexText = "Index " + i; myItems.add(listItem); indexVal += 1; } notifyDataSetChanged(); } public int getCount() { return myItems.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.item, null); holder.indexText = (TextView) convertView .findViewById(R.id.textView1); holder.caption = (EditText) convertView .findViewById(R.id.ItemCaption); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } //Fill EditText with the value you have in data source holder.caption.setText(""); holder.caption.setId(position); holder.indexText.setText("Index " + position); holder.indexText.setId(position); //we need to update adapter once we finish with editing holder.caption.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus){ final int position = v.getId(); final EditText Caption = (EditText) v; myItems.set(position, Caption.getText().toString()); } } }); return convertView; } class ViewHolder { EditText caption; TextView indexText; } class ListItem { String caption; String indexText; } } }

    Read the article

  • Proper way to 100% wakes my device?

    - by quiel
    Do you have better way to make the device awakes by 100%? I repeatedly call the acquire() but I'm not sure if that is correct. Or should I just call the acquire() once? Or should I make use of Intent.ACTION_SCREEN_OFF? public class MyServiceThatKeepsTheDeviceAwake extends IntentService { ... @Override public void onCreate() { super.onCreate(); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE, TAG); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); mWakeLock.acquire(); } // No release

    Read the article

  • Is it possible in Scala to force the caller to specify a type parameter for a polymorphic method ?

    - by Alex Kravets
    //API class Node class Person extends Node object Finder { def find[T <: Node](name: String): T = doFind(name).asInstanceOf[T] } //Call site (correct) val person = find[Person]("joe") //Call site (dies with a ClassCast inside b/c inferred type is Nothing) val person = find("joe") In the code above the client site "forgot" to specify the type parameter, as the API writer I want that to mean "just return Node". Is there any way to define a generic method (not a class) to achieve this (or equivalent). Note: using a manifest inside the implementation to do the cast if (manifest != scala.reflect.Manifest.Nothing) won't compile ... I have a nagging feeling that some Scala Wizard knows how to use Predef.<:< for this :-) Ideas ?

    Read the article

  • Threading in java vs C#

    - by ffayyaz
    I need a little confirmation over something i am confused at . I know how threads work in java. new DialList(string a , string b).start(); // where DialList is a class public class DialList extends Thread { public DialList(String a, string b) { FilePath = a; ThreadLogFile = b"; } public void run() { // some code to run in different thread } } Now i want to run same code in C# , Shall i put the code which is in run() into a method and do something like Thread t = new Thread (runcsharp); // Kick off a new thread t.Start(); static void runcsharp() { // code } or is there some other way to do it ?

    Read the article

  • any way to simplify this with a form of dynamic class instantiation?

    - by gnychis
    I have several child classes that extend a parent class, forced to have a uniform constructor. I have a queue which keeps a list of these classes, which must extend MergeHeuristic. The code that I currently have looks like the following: Class<? extends MergeHeuristic> heuristicRequest = _heuristicQueue.pop(); MergeHeuristic heuristic = null; if(heuristicRequest == AdjacentMACs.class) heuristic = new AdjacentMACs(_parent); if(heuristicRequest == SimilarInterfaceNames.class) heuristic = new SimilarInterfaceNames(_parent); if(heuristicRequest == SameMAC.class) heuristic = new SameMAC(_parent); Is there any way to simplify that to dynamically instantiate the class, something along the lines of: heuristic = new heuristicRequest.somethingSpecial(); That would flatten that block of if statements.

    Read the article

  • How do I create a dynamic method in PHP?

    - by sandelius
    I'm trying to extend my ActiveRecord class with some dynamic methods. I would like to be able to run this from my controller $user = User::find_by_username(param); $user = User::find_by_email(param); I've read a little about overloading and think that's the key. I'v got a static $_attributes in my AR class and I get the table name by pluralizing my model (User = users) in this case. How do I do this? All models extends the ActiveRecord class.

    Read the article

  • Criteria: search for two different entity classes...

    - by RoCMe
    Hi! I have a "super entity" SuperEntity and three entities ChildEntity1, ..., ChildEntity3 which extends the super class. It's easy to search for all entities in the database, i.e. we could use session.createCriteria(SuperEntity.class); It's no problem to search for one specific entity type, too, just replace the SuperEntity with any of the children to look for entities of that type. But I have a problem when allowing 'multiple choice' for the types. I.e., it could be neccessary to search all entities of type 1 and 2, but not of type 3. A first idea was to create two independent queries and join the results in a final list - but that would destroy the paging which uses offset and limit functionality of the database... Is there a possibility in Criteria to join two different queries in one single result list? Kind regards, RoCMe

    Read the article

  • Override existing AS3 classes

    - by purga
    For a custom derived class "Vector2" from flash.geom.Point, when trying to override the clone() method (similar to add(), subtract() methods that will return the type itself), it will always complain about incompatible overriding 'cuz the return type has been altered from "Point" to "Vector2". import flash.geom.Point; public class Vector2 extends Point { //Constructor is good public function Vector2(x:Number = 0, y:Number = 0) { super(x,y); } // Error: Incompatible overriding override public function clone():Vector2 //return type has to be "Point" { return new Vector2(this.x , this.y); } } How can we correctly reuse/override the methods provided by the super classes as supposed to create our own one (e.g. : a new clone1() method), or simply we just can't? Thanks.

    Read the article

  • Why javabeans framework create the IndexedPropertyDescriptor for the NON index method

    - by George Macus
    I'm not familiar with java beans framework, in the below scenario, I got the IndexedPropertyDescriptor for the method getFooWithX, could someone explain why? public class IntrospectorTest { public static void main(String[] args) throws IntrospectionException { BeanInfo info = Introspector.getBeanInfo(SubClass.class); PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); for (int i = 0; i < descriptors.length; i++) { System.out.println(descriptors[i].getClass().getName() + ":" + descriptors[i].getName()); } } } abstract class BaseClass { public abstract Object getFoo(); } abstract class SubClass extends BaseClass { public Object getFooWithX(int x) { return null; } } and the result will be: java.beans.PropertyDescriptor:class java.beans.PropertyDescriptor:foo java.beans.IndexedPropertyDescriptor:fooWithX Why?

    Read the article

  • [Android] How to launch an Activity without a UI?

    - by fjmustak
    Is it in any way possible to launch an activity from the main function without having a UI? i.e. is there a way to create a sort of "wrapper" around another activity, i.e. by launching the main activity, it takes you to another activity automatically. If that is not possible, is there a way to remove the main activity from the stack so that clicking the back button does not take you to a blank UI? Here's an example of what I'm trying to do: public class WrapperActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-1212")); startActivity(intent); } }

    Read the article

  • Need help with this question: Write Java code which reads numbers from the keyboard.....

    - by Chris
    Write Java code which reads numbers from the keyboard until zero is entered. Only the positive numbers entered are to be added to a variable-sized collection. This is what I have so far: import java.lang.*; import java.util.*; import java.io.*; import java.net.*; public class Demo1App extends Object { public static void main(String[] argStrings) throws Exception { ArrayList myArrayList = new ArrayList(); Scanner input = new Scanner(System.in); System.out.println ("NUMBERS:"); while (int input > 0) { myArrayList.add(input); } while (int input < 0) { System.out.println ("ENTER NUMBERS GREATER THAN 0!"); } } } This code doesn't work, I'm not sure why but any help with it would be appreciated.

    Read the article

  • Extending folder (LiveFolder?) class

    - by yamsha
    So, I noticed that I can organize apps into folders (HTC Incredible). However these folders are fairly limited in their capabilities. I want to implement an activity that extends the "base" folder activity (at the very least I want to add the ability to rearrange items in folders), but I can't figure out the class name... So, what's the name of the class that is used when adding a "New Folder" to the Home screen? PS I did take a look at the Android developer website. But the discussion there revolves mostly around content providers. I assume that's not quite what I need since I'd have to create a separate content provider for each new folder, or am I misunderstanding something?

    Read the article

< Previous Page | 79 80 81 82 83 84 85 86 87 88 89 90  | Next Page >